JOML-CI / JOML

A Java math library for OpenGL rendering calculations
MIT License
728 stars 104 forks source link

[Suggestion] Immutable types #300

Closed Monniasza closed 3 years ago

Monniasza commented 3 years ago

I'd like to have immutable versions of all types in this library. The new types would have 'const' appended to names of current types Example: Vector3d -> Vector3dconst. THey would share common interface

httpdigest commented 3 years ago

Yepp, those will come with JOML 2.0 once Valhalla with value/inline types becomes a thing. Due to the non-deterministic allocation/inline/escape/stack-replacement behaviour of the JIT, the design choice for JOML's types was: you allocate yourself when you know you need to and JOML mutates existing instances, provided by you. This will change with JOML 2.0 and Valhalla.

Monniasza commented 3 years ago

These can be still done as references. I'd intend to use them as map keys.

httpdigest commented 3 years ago

There are already read-only/constant interfaces/views with which you can achieve this. See e.g. Vector3dc. And when you want to avoid other code mutating the same instance, then simply never share instances: Whenever you give an instance away to some other code, simply make a new copy of that instance.