Should I use Buffers or primitive variables with lwjgl?

Started by Cornix, October 03, 2013, 19:05:08

Previous topic - Next topic

Cornix

Hi there.

I was thinking today, there are plenty of LWJGL functions which can take either Buffers or primitive data types as parameters, and they return either a primitive data type or write into a given buffer.
I usually used primitive data types up to this point because they seem more simple to use. However, I was wondering, if there is any kind of performance difference between these 2 methods.
It might be, that every method which uses primitive data types just creates a buffer internally and this would lead to huge amounts of temporarily created buffers.

So I d like to ask those people who know the answer: Is there a difference? Would it be better to use Buffers?

Thank you very much.

spasi

The functions that receive or return primitive values use preallocated and reusable buffers, so there is no allocation cost. The buffers are associated with the ContextCapabilities object (which is per-context), that means they're also naturally thread-safe to use and no locks are involved.

In practice, you shouldn't see any measurable difference between the primitive and the buffer versions. In theory, the primitive versions might be marginally quicker when LWJGL checks are enabled, since in most cases they don't need to check if the source/target buffer has enough space for the operation.

Cornix