On Wed, May 21, 2008 at 9:36 AM, 이희승 (Trustin Lee) <[EMAIL PROTECTED]> wrote:
> > On Tue, 20 May 2008 22:56:03 +0900, Daniel Wirtz <[EMAIL PROTECTED]> > wrote: > > And what about slicing contents from the buffer? Does it *copy* the >> contents to a new bytebuffer or is a composite buffer used in the >> background >> to achive zero-copying when slicing over multiple (including partial) >> buffers? Or is it not meant to deal with a ByteBufferQueue this way and >> reuse a duplicated instance instead for further reading? >> > > For now, slicing might copy or might not copy depending on the specified > position and length. If the requested slice belongs to one ByteBuffer, no > copy will be performed. Otherwise a new ByteBuffer will be created and > zero-copy in not realized. Decoder implementor needs to understand this and > implement the decoder properly to achieve zero-copy. State machine based > decoders should not have a problem with this IMHO. Please let me know if I > am missing something. > > To provide more perfect zero-copy, we need to introduce a new type which > wraps one or more ByteBuffers. Its implementation could be similar to > ByteBufferQueue, but it's different in that its length is fixed and it looks > exactly like ByteBuffer. It's because ByteBuffer cannot be extended. > Should we provide this? I think we can. The problem is that we need to > write a whole bunch of JavaDoc for the new buffer class, although it's just > one time task. > Hi Just a note about the CompositeByteArray implementation that I've attached to DIRMINA-489. If it was used as the underlying implementation for the ByteBufferQueue then any of these behaviours could be easily provided. *Always provide a single ByteBuffer* (even if this involves a copy) composite.slice(index, length).getSingleByteBuffer() *Provide an Iterable<ByteBuffer>* (thereby avoiding a copy) composite.slice(index, length).getByteBuffers() *Provide a wrapped ByteBuffer* (which may or may not be composite, and again avoiding a copy) composite.slice(index, length) Simple! Of course, I'm possibly biased. :-) Cheers Rich
