3
我想分配一个直接 IntBuffer在Java中,比如说有十亿个元素(64位系统)。我知道的唯一方法是创建一个直接的ByteBuffer并将其视为直接的IntBuffer。但是,4 * 1,000,000,000超出Integer.MAX_VALUE,所以我的问题是:我如何实现目标?Java:直接IntBuffer的大小限制?
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");
非常感谢提前,
马库斯
如何创建一个二维缓冲区数组? – nafas
[java创建字节数组,其大小用长表示]的可能重复(http://stackoverflow.com/questions/1071858/java-creating-byte-array-whose-size-is-represented-by-a-长) –
这不是IntBuffer的限制,它是一个java限制。 java中的数组长度不能大于2^31。 –