lua-users home
lua-l archive

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



On 21-Jul-04, at 11:01 AM, Matthew Harmon wrote:

My questions are:

- How efficient is Lua when I redefine a function to the exact same thing
over and over?

It simply overwrites a pointer (in effect). The inefficiency is compiling the same thing over and over.


- Are the old "contents" of the symbol just garbage collected as normal?

yes.


- Is redefining the symbol enough to trigger the garbage collection?

no. The garbage collector triggers when it is ready to. But redefining the symbol is sufficient to make the previous value garbage collectable provided no other reference to that value exists.


- And, ultimately, is there any problem (other than performance) with
frequently re-loading the same chunk which keeps defining a symbol to the
same thing?

The potential problem is that somewhere you retain a reference to the value of the symbol; if so, these could mount up. This is because functions (unlike, say, strings) are not "interned"; each time you load a function definition, Lua creates a new function even if you think it is the "same" function.

This doesn't apply to, say, string or number values repeatedly being set to the same thing, because they really are the same thing.

R.