gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:18:01 24 4
gpt4 key购买 nike

我正在尝试制作堆外内存缓冲区。我想要非常大的缓冲区(比如 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

请帮助我。

最佳答案

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

例如:

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);
}

关于JAVA NIO Bytebuffer.allocateDirect() 超过 int 的大小限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24026918/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com