lua-users home
lua-l archive

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


I recently ran across some lua code similar to this:

    if ( ( GetUserName() == "Larry") or
         ( GetUserName() == "Curly") or
         ( GetUserName() == "Moe")  ) then
        Print("Dude, you're a stooge!")
    end

I suggested to the developer that this code would be faster:

    local name = GetUserName();
    if ( ( name == "Larry") or
         ( name == "Curly") or
         ( name == "Moe")  ) then
        Print("Dude, you're a stooge!")
    end

His reply was:
"... its actually better memory-wise to call the function four or
more times than it is to store a temporary variable. This is due to LUA's
memory management system."

Is this true? Do "local" variables have a life beyond their scope? Do they
waste memory?

Inquiring minds want to know... Who's a stooge? ;-)

-- 
Enjoy,
George Warner,
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)