lua-users home
lua-l archive

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



Heap fragmentation is a bitch for sensors that have to be run
continuously without reboot for a long time. How hard is it to add
heap defragmentation to Lua's GC?

It's not only the GC, it's also the fact that Lua must call realloc() quite a bit in order to grow its internal data structures. It's not Lua's fault, it's just the most natural way to handle the data structures found in Lua. After some testing, I found out that a seggregated allocator (such as Doug Lea's dlmalloc) can handle fragmentation better than other allocators, but it has some memory overhead itself (about 1k for a "standard" dlmalloc, although it could be reduced). I didn't have a change to "benchmark" Ralph's allocator yet.
There are other ways though. You might find that for some applications you're better off turning off the GC completely. Also, for applications that make extensive use of buffers, it might be useful to allocate the buffer in a C module, return it as a light userdata, and use it for consequent requests. Kinda ugly, but it's a way to avoid the GC.

Best,
Bogdan