【发布时间】:2015-10-07 11:03:03
【问题描述】:
我想在 Java 中分配一个 direct 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");
非常感谢,
马库斯
【问题讨论】:
-
如何创建一个二维缓冲区数组?
-
这不是 IntBuffer 的限制,而是 java 的限制。 java中的数组长度不能大于2^31。
-
你是对的,但是我的缓冲区大小不需要超过 2^31 个整数,问题是由于(必要的?)通过 ByteBuffer 绕道而出现的。
标签: java bytebuffer addressing