Right, but the caveat is that the duplicate buffer shares the same memory
space.  Calling duplicate then changing the contents would be a no-no.
Without drilling down and paying attention, it would be easy to think that
duplicate actually duplicates the buffer instead of creating a slice.

On Tue, May 22, 2018 at 8:42 AM, Emmanuel Lécharny <[email protected]>
wrote:

>
>
> Le 22/05/2018 à 14:02, Jonathan Valliere a écrit :
> > Duplicating the buffer most likely temporarily moves the position also.
> If
> > you submit a buffer to be written, don’t do anything with it until after
> it
> > it written.
>
> ByteBuffer.duplicate() - which is called by IoBuffer.duplicate() -
> creates a new Direct/HeapBuffer based o the byte[] and all the
> associated flags (limit, capacity, position makrk). The original buffer
> isn't altered.
>
> In other words : it's safe.
>
> --
> Emmanuel Lecharny
>
> Symas.com
> directory.apache.org
>
>

Reply via email to