IntBuffers

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

IntBuffers

lpvb
I noticed in the docs that a lot of methods take IntBuffers as an alternative to arrays. Can anyone explain this reasoning? Is it faster or something?
Reply | Threaded
Open this post in threaded view
|

Re: IntBuffers

gouessej
Administrator
Hi

When you pass an array in case a direct NIO buffer could be passed instead, a new direct NIO buffer is created. Moreover, such buffers are used to communicate with native APIs. Methods taking arrays are there for convenience but shouldn't be used, passing buffers has a lower memory footprint and is faster especially when you use them correctly. Keep in mind that indirect NIO buffers are allocated on the Java heap but they can't be passed to some methods accepting buffers and direct NIO buffers are allocated on the native heap which is under your responsibility (you have to release native resources by yourself and there is no public API to do that in Java 1.7).
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: IntBuffers

Xerxes Rånby
In reply to this post by lpvb
lpvb wrote
I noticed in the docs that a lot of methods take IntBuffers as an alternative to arrays. Can anyone explain this reasoning? Is it faster or something?
All methods that share data at the same time with the OpenGL driver implementation and Java must be passed as a "memory pinned" java NIO buffers. By using "memory pinned" java NIO buffers guards from crashes that will happen if the java garbage collector is allowed to move the buffer while it is in use by the OpenGL driver thus it is a technical requirement. Functions where OpenGL must make a copy of the memory content according to opengl specification can be allowed to still use arrays.