

This applies to the POJO wrappers themselves, not the off-heap memory they point to. Strategy #2īuffer instances passed to LWJGL APIs are never mutated. You can easily have an application where all buffer call sites are monomorphic. DirectIntBufferU for the IntBuffer abstract class). If users are also careful with alignment, all buffers will be instantiated from the same concrete class on all platforms (e.g. Views are always naturally aligned to the element type. This mix of concrete types means the JVM will have a harder job optimizing code.Īll ByteBuffer instances created by LWJGL are in the native byte order. when dealing with data managed by native libraries). An application that allows heap buffers cannot avoid direct buffers (e.g. An application that uses direct buffers exclusively can do anything.

They make a lot of call sites bimorphic or even megamorphic. They needlessly complicate all code paths that accept NIO buffers. Heap buffers might be cheap to allocate and trivial to cleanup (via standard GC), but they force data copies when passed to native code. All buffers must be off-heap ( DirectByteBuffer and derivatives) to be accepted by the LWJGL API. LWJGL does not support (or even work on) Android yet, but it's almost certain that different strategies will have to be used there. Decisions made may or may not be optimal on other JDKs/JVMs. LWJGL requires Java 8 and we have tested with OpenJDK, Oracle JDK, Azul Zulu, IBM JDK.

The following applies to the platforms LWJGL supports: Linux, MacOS, Windows. The purpose of this post is to explain how LWJGL 3 addresses these issues. There are a lot of complains about how they're designed, how they're used (or not used) in various APIs, how they perform. In the meantime, NIO buffers have been getting a lot of bad rep, which is mostly justified. The primary goal of the library is to provide the best performance/usability/safety balance possible, at least until Project Panama is released (hopefully) in Java 10. Like its predecessor, it provides bindings to popular native libraries via JNI and uses NIO buffers to pass data around. It is a clean rewrite of LWJGL, officially released on June 2016. Access the contents of buffers managed by external libraries.Fill buffers with data and pass them down to native code, without expensive copies.Using java.nio and direct ByteBuffer instances, Java developers could: Java 1.4 finally made it possible to access off-heap memory from Java and efficiently inter-operate with native code.
