fragmentation and Lua script

classic Classic list List threaded Threaded
2 messages Options
pau
Reply | Threaded
Open this post in threaded view
|

fragmentation and Lua script

pau
Perhaps I am doing lots of crazy stuff, but my game doubles its memory
usage after somebody using it for a while. I am using standard Lua 4.0
and forcing garbage collection every 5 seconds or so.

But If I force gabarge collection every frame, the game slows down quite 
a bit, but then memory seems not growing too out of control.

I am unable to detect serious memory leaks using dmalloc, so it leads
to think of defragmentation. Then I checked the memory usage using
mallinfo(), it shows:

$1 = {arena = 28611460, ordblks = 10885, smblks = 26349, hblks = 17, hblkhd = 7225344, 
  usmblks = 37208964, fsmblks = 939616, uordblks = 13484524, fordblks = 15126936, keepcost = 880}

So arena - uordblks = 15126936, roughly 15M(!) fragmented mallocs!

Is this considered ordinary? How do I avoid lots of fragmentations? My
game is using lua scripts extensively, including many non-permanent
small string, small table and closure creation in every frame cycle.

Regards,
.paul.

Reply | Threaded
Open this post in threaded view
|

Re: fragmentation and Lua script

J. Perkins-2
[hidden email] wrote:
Is this considered ordinary? How do I avoid lots of fragmentations? My
game is using lua scripts extensively, including many non-permanent
small string, small table and closure creation in every frame cycle.

It you grab the latest F4 snapshot (located at http://www.379.com/f4), you can pull out the memory manager I'm using. It "pools" < 4K allocations together into larger pages, avoiding memory fragmentation. You can also see how I patched the Lua code to use it. It's also a lot faster than the std mem operators. I don't notice the Lua gc blips in my development code any more, though I'm still scaling up the content.

Jason
379