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.
I got the point. Indeed even if I got the right timing and don’t mess with TempVars, maybe another future change on engine will do, so I’ll have to retest this feature every time a release came.
I’ll keep that on mind, if I need it, I’ll extend and make my own TempVars. Thanks guys, I loved this “trick”
Yep, my point is that with threading don’t control the moment a tempVar will be picked from the stack, so you could end in a situation where you need 6 of them randomly.
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…