4

我想在 Java 中分配一个直接的IntBuffer,比如十亿个元素(64 位系统)。我知道的唯一方法是创建直接 ByteBuffer 并将其视为直接 IntBuffer。但是,4*1,000,000,000 超过了 Integer.MAX_VALUE,所以我的问题是:我怎样才能实现我的目标?

int numInts = 1_000_000_000;
IntBuffer i = IntBuffer.allocate(numInts); // works!

ByteBuffer bb = ByteBuffer.allocateDirect(4*numInts); // does NOT work: integer overflow
IntBuffer ib = bb.asIntBuffer();
System.out.println("This will never be printed");

非常感谢提前,

马库斯

4

1 回答 1

1

也许您可以尝试创建一个基于 BigInteger 的缓冲区。有些人在 Github 上创建了一个“BigIntbuffer”类,可以激发你的灵感: 见这里

于 2015-10-07T11:12:28.323 回答