lua-users home
lua-l archive

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


> I am having trouble with Lua garbage collection. I am using 
> Lua as an agent system for a real time game. Basically the 
> mark and sweep system takes to long. Having a small threshold 
> requires garbage collecting regularly, which means marking a 
> lot of data regularly and cleaning up a little of it. The 
> marking takes to long to do so regularly. Having a high 
> threshold requires marking less regularly which is better but 
> cleaning up loads of data in one sweep, which takes to long. 
> There is no good balance here. Has anyone found a way around this?

Don't cause anything to allocate during the real-time.

Seriously.

It was the only way to ship Amped: Freestyle Snowboarding.  No closures
could be generated on the fly.  No tables could be generated on the fly.
No strings could be generated on the fly.  The allocations were
identified, and pregenerated before the real-time ran.

So, instead of filling in myTable like this in the real-time:

myTable = {}
myTable.Var1 = 5
myTable.Var2 = "Hi"

myTable was made global, generated before the real-time loop, with all
the possible fields in place.

In other words, either make the necessary changes to your real-time Lua
codebase (by breakpointing the realloc function for Lua to determine
where memory allocations are), or don't count on using Lua during your
real-time.  :(

-Josh