我正在尝试制作堆外内存缓冲区。我想要非常大的缓冲区(比如 10GB)。
我听说jvm堆有时会因为full 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
请帮我。
你不能让单个缓冲区那么大。时期。您可以制作几个较小的,并根据需要在自己的代码中进行选择。这就是你所能做的。
e.g.:
ByteBuffer[] myBuffers = new ByteBuffer[howMany];
for (int x = 0; x < howMany; x++) {
myBuffers[x] = ByteBuffer.allocateDirect(prettyBig);
}
and then
byte getByte(long index) {
int bufx = index / howMany;
int bx = index % howMany;
return myBuffers[bufx].get(bx);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)