lua-users home
lua-l archive

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



On Apr 10, 2007, at 3:56 PM, Sam Roberts wrote:

What using luaL_ref() does is basically transform a lookup of a string
in the "hash" part of a predefined table to a lookup of a number in
(hopefully) the array portion of a (different) predefined table.

"hopefully", because its not clear to me that the reference system
*guarantees* that all references will stay in the array part of a table.
If it doesn't guarantee this, using references will devolve to a hash
table lookup of a number, which is what you appear to be trying to avoid
in the first place.


"Use the source, Luke!" :-)

The luaL_ref mechanism keeps a linked list of 'recycled' references right in the array part of the registry table in such a way that the table will never have any 'gaps'. You will always get the fast, constant-time lookup behavior. On the downside: the registry table can never shrink. Once you use a million references those 12-16 million bytes will stay allocated until the lua_State object is destroyed.


--
Gé Weijers