lua-users home
lua-l archive

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


> In my opinion the only real tool against memory fragmentation is a
> moving (or copying, or compacting) garbage collector. The LUA GC is a
> mark&sweep one, so it does not compact memory and neither does the
> ordinary manual malloc+free (as in C) or new+delete (as in C++) memory
> management. Fragmentation issues do appear in C or C++. There are lots
> of literature on compacting or moving garbage collection (and there is
> a GC mailing list, even if it is a bit quiet these days).

Useful resources here:
http://www.memorymanagement.org/
http://lua-users.org/wiki/GarbageCollection
http://lua-users.org/wiki/MemoryAllocation

Compacting may not be very good solution for games as it may take to
much time. You don't really want to spend 10-20% of your CPU time moving
memory around and have to deal with all the indirection as well. Some
points are made here:
http://www.memorymanagement.org/articles/recycle.html#copying 

I think a lot of fragmentation problems are down to the allocation
algorithm. There is some useful info here and I think this allocator
looks pretty good. I think I pulled it off this list a while ago. Its
fast and should be good for a scripting system allocating and
deallocating little blocks of similar sizes.
http://g.oswego.edu/dl/html/malloc.html

It wont solve the fragmentation problem but it might reduce it to an
acceptable level. If you try not to create many objects at runtime you
will probably suffer less as well:
http://lua-users.org/wiki/OptimisingGarbageCollection



> [Sorry for mentionning another language on the Lua mailing list, but I
> think that there are cases where Lua might not be the best solution]

There is nothing wrong with suggesting other solutions. I wish some more
Lua comparisons would appear on the wiki: 
http://lua-users.org/wiki/LuaComparison

This list and Luas progress is quite pragmatic. If you were to
demonstrate features of Ocaml that you liked and would benefit Lua you
might find them included. The authors are intending adding a
generational GC to Lua so perhaps you could shed light on this and/or
other optimisations.

Nick