Skip to content

OpenCL uses PointerBuffer.allocateDirect which is discouraged and a performance issue #1615

@devent

Description

@devent

Hello. I wonder why does the OpenCL implementation uses PointerBuffer.allocateDirect and not the MemoryStack?

As from the LWJGL documentation PointerBuffer.allocateDirect is discourage and slower than MemoryStack.

https://blog.lwjgl.org/memory-management-in-lwjgl-3/

Use of ByteBuffer.allocateDirect() is highly discouraged.
It is slow, much slower than the raw malloc() call. A lot of overhead on top of a function that is already slow.
All of that contributed to users adopting one or more bad practices when dealing with LWJGL code:

Using buffer instance pools. (which JME3 indeed uses)
Using global buffer instances, often not in a concurrent-safe way.

[...]
Always prefer stack allocation.
The solution is the org.lwjgl.system.MemoryStack class that exposes an API for stack allocations.

Would there be any interest in replacing the PointerBuffer.allocateDirect with MemoryStack? Or was there a deeper reason why MemoryStack wasn't used?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    tracked

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions