[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Structure of Lua (In C)
- From: Olivier Hamel <evilpineapple@...>
- Date: Sat, 04 Jul 2009 20:42:25 -0400
Peter Cawley wrote:
Alright, pretty close to the image/concept that I'd formed. Thank you to
everyone for clarifying this!
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.