In our application we have a lot of large static models that work great in native buffers but we also create a lot of dynamic geometry with dynamic texture mappings. If we switch our entire application to use Heap based buffers our 3D performance slows to a crawl. Recently we have been running into problems where the allocation of so many little native buffers has started overwhelming the garbage collector and our application crashes when we run out of native memory. We would like the ability to decide what buffers are allocated to native memory for performance and what buffers are allocated to the Heap for stability. I am sure other projects would find the extra control over memory allocation useful for similar specific optimizations.
In order to do this i have created an interface for a buffer factory with the default implementation being the exact same as BufferUtils. I also added a enum called DataContext that adds context to the data that will be stored in the buffer being allocated. This allows for more advanced performance optimizations from within our own buffer factory. It also allows us to clean up native buffers without having to rely on the garbage collector. This will allow our application to have much more control over the memory allocated in our 3D component and it becomes less like a black box.
Implementation notes: I provided backwards compatible methods for every constructor and method i had to overwrite. I also implemented the enumeration in a way that is complaint with java 1.4 and lower.
Patch to add memory allocation factory