LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.81k stars 639 forks source link

Why LWJGL uses arrays for pointers instead of AtomicIntegers? #1004

Closed CiroZDP closed 1 month ago

CiroZDP commented 2 months ago

Question

Java provides us with several classes for this purpose: AtomicInteger and AtomicLong (there are more). These classes hold a value which is usually a number or a decimal number. The values ​​contained in these classes can be changed at any time and can be used as an argument in a method.

For example, there are functions in glfw that allow you to get the mouse position, these functions use an array of doubles to represent a pointer, but, in my humble opinion, I think it would be a good idea to replace these arrays with something that "makes more sense".

Some ideas: ALT

Thanks in advance.

EDIT: There are no atomical classes for decimal numbers, but you can use AtomicReference<Double> dptr = new AtomicReference<>(); for creating a atomical reference to any double number.

knokko commented 1 month ago

Atomic integers (and other atomic types) are meant for synchronization between threads, and are probably much more expensive than simple arrays. Besides, they can only store 1 value, whereas some LWJGL function require longer arrays.