arrays vs buffers for JNI

I’ve noticed that in lwjgl, the functions which would require an array in opengl require bytebuffers or floatbuffers in lwjgl. is this for speed?

i need to be able to pass an array to a function i’ve written, and return one.

what would be faster, using a jbytearray, or converting my array to a buffer, sending it, having the method return a buffer, and converting it to an array?

Yes, it’s for speed. Direct ByteBuffers are the absolute fastest lowest overhead way of getting data to OpenGL. If you’re actually processing that data on the CPU, do it in arrays first then send it all at once to the buffer to transmit to OpenGL.

Cas :slight_smile:

Half if not all of the reason for Direct Byte buffers is for faster marshaling of data through JNI. It really is the correct way to do things with C esp if they are passing data back. Remember a java array does not look like a C array. But a C array looks like a Direct Byte buffer. More or less.

thanks for clearing that up. it had been nagging at me since i first started with lwjgl.
and of course that’s useful to know if i ever write my own JNI library for anything.