lua-users home
lua-l archive

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

Peter Cawley wrote:
Where possible, when two things have the same lifetime, the Lua source
likes to allocate them as one unit. Generally, this improves
efficiency (both execution time and memory usage). If you're going to
allocate a lua_State and global_State as one unit, then you need to
know the size of that unit. The obvious choice might be
sizeof(lua_State) + sizeof(global_State), but that would not guarantee
correct alignment on the global_State, hence a struct of the two is
used, as this will add whatever padding is required to give correct
alignment on the global_State. Also, the global_State cannot be
managed by the garbage collector, as it contains the state for the
garbage collector. Furthermore, the primary lua_State cannot be
managed by the garbage collector. LG thus neatly contains all of the
objects which are outside of the garbage collector.

At least, that is my interpretation of the source code.
Alright, pretty close to the image/concept that I'd formed. Thank you to everyone for clarifying this!