lua-users home
lua-l archive

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


> What's wrong with my suggestion to use extra allocation and reference
> counting for strings?

Extra allocation: you can only use extra allocation if you allocate space
for variables, not for values. In Perl, each variable has its own buffer,
and a string assignment actually copies the string from one buffer to
the other. So it can do extra allocation in a variable's buffer. In Lua,
each variable points to a string; assignment assigns the pointer. So,
it doesn't make sense to have "extra allocation" in the space used by
a fixed string.

The scheme used by Perl makes some string operations much faster than
in Lua, but makes several other operations much slower. For instance,
the simple creation/release of local variables take some time. (If you
simply declare a dummy `my' variable in a function it slowdowns the call
by more than 10%).

Reference counting: Lua is not statically typed. To do reference
counting for strings, you will have the overhead of reference counting
everywhere. Then it is better to simply change the GC mechanism to
reference counting.

-- Roberto