lua-users home
lua-l archive

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


On Sat, Jul 4, 2009 at 11:52 PM, Olivier Hamel<evilpineapple@cox.net> wrote:
> Now all I need to figure out is what the LG
> structure does. (No bloody clue. It seems to be some sort of marker to
> specify the size of an empty global state and one lua state. Right?)

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.