[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: GC and userdata objects
- From: Francisco Olarte <folarte@...>
- Date: Wed, 11 Apr 2018 12:16:34 +0200
On Wed, Apr 11, 2018 at 11:17 AM, Dibyendu Majumdar
> One practical issue currently with Lua's GC is it slack of knowledge
> about memory held by userdata objects. This makes the GC calculation
> pretty erroneous - and userdata objects are pretty common I presume.
> Is there a way to make the GC aware of the memory held by a userdata
> object - maybe through an C API call?
The GC already knows about part of the memory held by the object.
The other is difficult to define.
I mean. We use C++. We put the main object into the lua heap, lua
knows about it. But our objects hold other memory consuming resources.
Some are owned, some are shared, some are ref counted, some are not.
And some are not even ours, like windows handles, file buffers and the
like, and some hold more resources. It would be very difficult for us
to tell you how much memory an object uses from C++.
> In my view this would be a very useful enhancement to Lua.
It could be, but you would need to make it much more smart to take
into account memory external to lua heap. AFAIK the GC works only
across a sinle lua state.