Swap should be better done native?
Martin Buchholz
martinrb at google.com
Thu Apr 1 14:55:55 PDT 2010
On Thu, Apr 1, 2010 at 05:32, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
>> How can 4 put(byte) be converted into one put(int)?
>>
> See the following code snippets ...
>
> ===================================================
> Codesnippet from EUC_TW$Encoder:
> dst.put(SS2);
> dst.put((byte)(0xa0 | p));
> dst.put((byte)(db >> 8));
> dst.put((byte)db);
> ===================================================
> Alternative 1 codesnippet:
> dst.putInt((SS2 << 24) | (0xa0 << 16) | (p << 16) | db);
Ahhh, I see. Direct buffers are optimized to use Unsafe.putInt
on platforms where unaligned writes are possible (i.e. x86).
Some problems with that:
- direct buffers are difficult to use, because the GC
cannot manage them well.
- this only works on x86
- this doesn't work with other subclasses of ByteBuffer
- I would think optimizing the case of ByteBuffer with arrays
(ie. hasArray() is true) would be more important.
Martin
More information about the nio-discuss
mailing list