JAVA NIO Bytebuffer.allocateDirect()对int的大小限制

我正在尝试制作堆外内存缓冲区。 我想要非常大的(如10GB)缓冲区。 我听说jvm堆有时会冻结,因为完整的GC。 所以,我尝试使用java.nio.ByteBuffer创建缓冲区。

但是,我遇到了很大困难!

java.nio.ByteBuffer.allocateDirect(int size) 

函数只支持整数。 但我想要更大的尺寸。 我能做什么? 我该怎么办? 请帮我堆叠溢出大师。

我的开发环境是macbook pro,i7 2.4ghz,16gb ddr3,250ssd,osx 10.9,eclipse kepler x64。

我尝试解决问题:

 ByteBuffer buffer = ByteBuffer.allocateDirect(1024*1024*2000); ByteBuffer buffer1 = ByteBuffer.allocateDirect(1024*1024*2000); ByteBuffer buffer2 = ByteBuffer.allocateDirect(1024*1024*2000); ByteBuffer buffer3 = ByteBuffer.allocateDirect(1024*1024*2000); 

但这不起作用。 仅重新分配内存1024 * 1024 * 2000

请帮帮我。

你不能制造一个大的缓冲区。 期。 你可以制作几个较小的,并在你自己的代码中根据需要选择它们。 这就是你所能做的一切。

例如:

 ByteBuffer[] myBuffers = new ByteBuffer[howMany]; for (int x = 0; x < howMany; x++) { myBuffers[x] = ByteBuffer.allocateDirect(prettyBig); } 

接着

 byte getByte(long index) { int bufx = index / howMany; int bx = index % howMany; return myBuffers[bufx].get(bx); }