BufferUtils

Started by awesomelemonade, March 17, 2016, 23:02:57

Previous topic - Next topic

awesomelemonade

Hi all,

Apparently, I am having trouble creating big float buffers through BufferUtils.createFloatBuffer.

FloatBuffer buffer = BufferUtils.createFloatBuffer(1049580042); //or even Integer.MAX_VALUE
If I do the above line, it would return an illegal argument exception with a negative capacity though I clearly specified positive. According to the stacktrace I have below, I believe it is somehow the inner workings of nio Buffer. How should I resolve this issue?

Thanks in advanced,
Lemon

Stack Trace:
java.lang.IllegalArgumentException: Negative capacity: -4
	at java.nio.Buffer.<init>(Buffer.java:191)
	at java.nio.ByteBuffer.<init>(ByteBuffer.java:276)
	at java.nio.ByteBuffer.<init>(ByteBuffer.java:284)
	at java.nio.MappedByteBuffer.<init>(MappedByteBuffer.java:89)
	at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:119)
	at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306)
	at org.lwjgl.BufferUtils.createUnalignedByteBuffer(BufferUtils.java:204)
	at org.lwjgl.BufferUtils$2.malloc(BufferUtils.java:76)
	at org.lwjgl.BufferUtils.createByteBuffer(BufferUtils.java:107)
	at org.lwjgl.BufferUtils.createFloatBuffer(BufferUtils.java:167)
	at lemon.engine.evolution.Game.init(Game.java:133)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at lemon.engine.reflection.ReflectionUtil.invokePrivateMethod(ReflectionUtil.java:56)
	at lemon.engine.event.EventManager.callListeners(EventManager.java:66)
	at lemon.engine.control.GLFWWindow.init(GLFWWindow.java:44)
	at lemon.engine.evolution.Evolution.main(Evolution.java:54)

Kai

You are trying to create a ByteBuffer which is 1049580042 * 4 bytes large. This is larger than Integer.MAX_INT

awesomelemonade

rip...

Is there an alternative/hack type of thing, or should I just probably not be creating this big of a buffer anyway..

Kai

Quote from: awesomelemonade on March 17, 2016, 23:19:52
Is there an alternative/hack type of thing, or should I just probably not be creating this big of a buffer anyway..
You could of course always split your buffer into four "little" ones and then handle those  "virtual memory" regions yourself in your application, probably using a long to index into them.