I’m reading some engine code and noticed the use of TempVars. If I understood it right, this class is a “trick” to avoid instantiating commonly used classes and frequently called functions (loops), like Vector3f, Quartenions and such?
If that’s the case, may I use TempVars on my own code? (Following the correct use of it - get() and then release()).
Yes, but I wouldn’t recommend to use it, IMO.
The engine is made to not go over this limit, but you don’t know how many tempvars are used for an instant t. So you can easily go over and have unexpected crash in your code. Especially If you have a multi threaded achitecture that could pick the tempVars at different time.
If you have a situation where a quaternion should be instantiated on every frame, you’re better off with a temp class variable IMO. The memory overhead is really minimal.
If you have that very often, I suggest you make your own MyProjectTempVars, and only query from it, so you can control the depth of the stack.
Since I got a little lost on what you said about g1 collection and had to search to understand that is a new GC “system”, do you have a good article to start reading about it? It’s time to dig deep into GC…