directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vinod Panicker <vino...@gmail.com>
Subject Re: [mina] Changes on ByteBuffer
Date Wed, 20 Apr 2005 04:50:06 GMT
Hi Trustin,

On 4/19/05, Trustin Lee <trustin@gmail.com> wrote:
> Hi,
> 
> I realized implementing complex codecs using NIO ByteBuffers is not
> really easy task and the main reason is that its size is fixed.  So I
> added autoExpand property to MINA ByteBuffer.  If autoExpand is true,
> you never get BufferOverflowException or IndexOutOfBoundsException
> (except when index is negative).  It automatically expands its
> capacity and limit value.  This is useful especially when you create
> data whose length is dynamic:
> 
> String greeting = messageBundle.getMessage( "hello" );
> ByteBuffer buf = ByteBuffer.allocate( 16 );
> buf.setAutoExpand( true );
> buf.putString( greeting, utf8encoder );
> 
> NIO ByteBuffer is reallocated by MINA ByteBuffer behind the scene if
> the encoded data is larger than 16 bytes.  Its limit and capacity will
> increase by two times.

So what you're saying is that you will double the size of the buffer
if there is an over-allocation required? (if that is so, it would be
overkill)

> 
> There were also some changes due to introduction of auto expand property:
> 
> * duplicate(), slice(), asReadOnlyBuffer() is disappeared; I don't see
> any easy way to implement this functionality, and it is not used in
> most cases especially when all buffers are pooled.
> * autoExpand property replaces fork( int capacity ) method.
> * String getter/putter have been revamped.

duplicate() and slice() would be good things to retain IMO.

> 
> I hope you like all this improvements.
> 

Nice to have a ByteBuffer that behaves this way.  Just remembered that
when I was writing a prototype using MINA, the ByteBuffer was behaving
in an unpredictable manner.  I'll post it up.

Regards,
Vinod.

Mime
View raw message