lua-users home
lua-l archive

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

Just for fun, I've been thinking about modifying Lua memory management to make it more friendly for video game applications. One problem with using Lua in games is the occasional pauses for garbage collection.
I've come up with two ideas for possibly minimizing this problem:
The first idea is to add reference counting. This should reduce the amount of garbage that's generated, at the expense of slowing down the Lua program a little. Reference counting won't replace garbage collection, since it can't collect circular references, but it should reduce the need for garbage collection.
The second idea is to add a real-time garbage collector, perhaps based upon the treadmill algorithm. This should convert the garbage collection pauses into a general slowing-down of the Lua interpreter.
Both of these ideas require adding some code to the Lua interpreter everywhere a pointer to a heap object is written to. For reference counting you have to update the reference counts, for incremental garbage collection you have to update the list of items to be scanned.
That brings me to the issue of how best to modify the Lua sources to conduct the experiments. Since I'm just doing this on an experimental basis, I'm thinking that the easiest way to do this would be to compile the Lua sources using a C++ compiler, and then use smart pointer classes. That would make it easy to make sure I modify all writes to pointers to heap-based-objects.
If these experements turn out to be successful, I guess we might want to think about a more C-friendly way of making these changes. I guess some sort of macro would work.
Does anyone have any opinions on these ideas? Anyone tried anything similar?