View Single Post
11-05-10, 11:29 PM   #4
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
That's not true. When you use a local variable, the memory allocated for it is on the stack (by default Lua allows a maximum of 200 locals and function parameters).

When you declare an upvalue, that upvalue was initially a function (or chunk) local. When the function (chunk) returns and the variable is still in the scope of some closure, that variable is moved from the stack to the heap and future accesses to it from the closure costs an indirection.

I.e Using upvalues costs an extra 4 bytes of memory for the indirection, and is about 1 clock cycle slower. Obviously it doesn't really matter, since this is in nanoseconds.
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes

Last edited by Xinhuan : 11-05-10 at 11:31 PM.
  Reply With Quote