[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Garbage Collection] Advice needed
- From: Mark Hamburg <mark_hamburg@...>
- Date: Thu, 15 May 2008 09:48:51 -0700
This is definitely a challenge when using Lua proxies that point to
big objects.
The simpler case comes when you at least know the size of the object.
You can then just drive the GC forward by a corresponding amount when
allocating the objects. This sort of ignores the size logic inside of
Lua's GC but seems to mostly work. As long as your size estimates are
reasonably accurate, you don't need to be precise. Estimating on the
high side is generally better because it results in extra collections
instead of memory spikes and the former are generally less expensive.
The technique in:
http://lua-users.org/lists/lua-l/2007-06/msg00088.html
would appear to integrate better with the GC accounting logic, but I
would like some confirmation from the Lua team in that regard. I would
also be inclined to implement this by changing the proxies to consist
of a pointer and a size and keep track of the size to report as
released in the __gc metamethod in the object itself.
You could then actually manage the space for the objects using an
override on the new operator which would associate the memory with a
pool tied to a particular userdata object. Of course, if you were
going to do that, then you could actually go so far as to use the
environment table for the userdata to track the memory allocations and
use userdata creation as a replacement for malloc...
Mark