我想在 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");
非常感谢提前,
马库斯