Java:直接IntBuffer的大小限制?

时间:2015-10-07 11:03:03

标签: java bytebuffer addressing

我想在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");

提前多多感谢,

马库斯

1 个答案:

答案 0 :(得分:0)

也许你可以尝试创建一个基于BigInteger的Buffer。有些人在Github上创建了一个“BigIntbuffer”类,可以激发你的灵感: See here

相关问题