You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by afa654321 <af...@yahoo.com> on 2007/01/23 00:09:28 UTC

ByteBuffer Initial capacity limitation

Is there any limitation on the inital capacity of
"org.apache.mina.common.ByteBuffer"

The following line of code fails with the below-mentioned exceptoin:


int capacity = 2147480000; 
org.apache.mina.common.ByteBuffer byteBuffer = 
org.apache.mina.common.ByteBuffer.allocate(capacity);	

Exception in thread "main" java.lang.IllegalArgumentException: Buffer size
is too big: 2147480000
        at
org.apache.mina.common.PooledByteBufferAllocator.getBufferStackIndex(
PooledByteBufferAllocator.java:227)
        at
org.apache.mina.common.PooledByteBufferAllocator.allocate0(PooledByte
BufferAllocator.java:173)
        at
org.apache.mina.common.PooledByteBufferAllocator.allocate(PooledByteB
ufferAllocator.java:159)
        at org.apache.mina.common.ByteBuffer.allocate(ByteBuffer.java:235)
        at org.apache.mina.common.ByteBuffer.allocate(ByteBuffer.java:215)
        at
org.apache.mina.example.sumup.TestByteBuffer.main(TestByteBuffer.java
:25)

while the same request using NIO ByteBuffer succeeds:
		
"java.nio.ByteBuffer byteBuffer =  java.nio.ByteBuffer.allocate(capacity);"

This test was done on a Windows Enterprise 2003 64-bit, MINA Version 1.0.1,
JDK 5.0

Thx.
-- 
View this message in context: http://www.nabble.com/ByteBuffer-Initial-capacity-limitation-tf3061116.html#a8512079
Sent from the mina dev mailing list archive at Nabble.com.


Re: ByteBuffer Initial capacity limitation

Posted by Trustin Lee <tr...@gmail.com>.
On 1/23/07, afa654321 <af...@yahoo.com> wrote:
>
>
> Is there any limitation on the inital capacity of
> "org.apache.mina.common.ByteBuffer"
>
> The following line of code fails with the below-mentioned exceptoin:
>
>
> int capacity = 2147480000;
> org.apache.mina.common.ByteBuffer byteBuffer =
> org.apache.mina.common.ByteBuffer.allocate(capacity);
>
> Exception in thread "main" java.lang.IllegalArgumentException: Buffer size
> is too big: 2147480000
>         at
> org.apache.mina.common.PooledByteBufferAllocator.getBufferStackIndex(
> PooledByteBufferAllocator.java:227)
>         at
> org.apache.mina.common.PooledByteBufferAllocator.allocate0(PooledByte
> BufferAllocator.java:173)
>         at
> org.apache.mina.common.PooledByteBufferAllocator.allocate(PooledByteB
> ufferAllocator.java:159)
>         at org.apache.mina.common.ByteBuffer.allocate(ByteBuffer.java:235)
>         at org.apache.mina.common.ByteBuffer.allocate(ByteBuffer.java:215)
>         at
> org.apache.mina.example.sumup.TestByteBuffer.main(TestByteBuffer.java
> :25)
>
> while the same request using NIO ByteBuffer succeeds:
>
> "java.nio.ByteBuffer byteBuffer =  java.nio.ByteBuffer.allocate
> (capacity);"
>
> This test was done on a Windows Enterprise 2003 64-bit, MINA Version 1.0.1
> ,
> JDK 5.0


The default buffer allocator pools the buffer, so we thought pooling too big
buffer won't make sense.  If you want to create a bigger buffer, please
change the allocator:

ByteBuffer.setAllocator(new SimpleByteBufferAllocator());

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6