JStackAlloc for Vector and Matrix value types

I looking around the internet and I found this on the JBullet website JStackAlloc: http://www.javagaming.org/index.php/topic,18843.0.html

It’s used for value types such as Vectors and Matrices in JBullet, so that it minimizes garbage.  Also I think it can help make these types thread safe in Java, much like Structs in C#.  Would this be helpful to add to the core of JME3?  Since Vectors, Matrices, and other types like these shouldn’t create garbage when disposed, since are used a lot?

JBullet (just in case you don’t know): http://jbullet.advel.cz/

jME3 already has something very similar. A class called TempVars which is retrieved by any method that needs temp vars, it is stored in a ThreadLocal.

But doesn't that still create garbage because it's not a value type class, unlike float or int.  I don't know, but maybe I'm wrong.  I know you can't create a value type class in Java (unlike C# with structs), but I was thinking this was a work around for this problem.  :slight_smile:

The TempVars doesn't create or allocate garbage. A set number of vectors and matrices is created the first time TempVars is invoked from a thread and from then on those vectors and matrices are used. You simply retrieve a reference e.g TempVars.get().vect1. Even though a vector or a matrix is an object, that doesn't mean simply using them will create garbage, only if you allocate them explicitly using "new Vector3f (…)" etc then an allocation will occur.

Ok, thx for the clarification.  Keep up the good work.  :smiley: