|
Thanks that sounds great. In my case, they are all numbers. I expect them all to be GCed after the function is called, but it does seem like having fewer locals to temporarily hold them is a good idea. Sent from my BlackBerry 10 smartphone on the Rogers Wireless network.
This'll work more or less the same as it does in C, except for the role of the GC and dynamic typing. Every distinct variable you allocate needs to be de-allocated by the garbage collector once it goes out of scope. So if you declare a dozen variables, that is a dozen objects the GC needs to mark and collect. If you declare two variables and re-use them with objects of the same type, thats only two
variables to mark and collect.
Will there be any performance gain? Yes; fewer allocations and fewer GC collections, if the objects get collected at all (at the default Lua pause of 200, the GC often won start a cycle once the program drops into a state where memory usage stabilizes). Note, however, that dynamic typing clouds the issue. If you were to define 'a' first as a number, then later as a string, the variable could not be reused, and the only difference is that the GC might be able to collect the first number at some earlier time - though it is unlikely that it will, the GC working as it does. For an overview of the GC, see Roberto's Lua Performance Tips: www.lua.org/gems/sample.pdf On Wed, Jan 2, 2013 at 4:59 AM, Marc Lepage <mlepage@antimeta.com> wrote: Say I have an object with about a dozen properties A-L. |