lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

In other programming languages, I used to declare objects before loops in order not to re-create one at each loop, for instance in Java :
MyObject hello = MyObject.new();
for(...)
{
// use and reuse 'hello' here, without the overhead of recreating the object at each loop
}

In Lua, I often do the same:
local a = ""
for ...
a = ... -- use variable a, change its value, etc. (here variable 'a' is 'non-local' thus with no indexed search)
end

Would it be better Lua programming (in terms of *speed* optimization) to do directly:
for
local a = ... -- because here the variable 'a' is local and not 'non-local', thus very quickly resolved (indexed) even if recreated at each loop
end

Thank you for your thoughts and comments about it!
Genio

_________________________________________________________________
Personnalisez votre Messenger avec Live.com http://www.windowslive.fr/livecom/