I want to allocate a direct IntBuffer in Java with, say, a billion elements (64-bit system). The only way I know of is creating a direct ByteBuffer and viewing it as a direct IntBuffer. However, 4*1,000,000,000 exceeds Integer.MAX_VALUE, so my question is: how can I achieve my goal?
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");
Thanks a lot in advance,
Markus