[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: GC and userdata objects
- From: Dibyendu Majumdar <mobile@...>
- Date: Wed, 11 Apr 2018 20:12:55 +0100
On 11 April 2018 at 11:16, Francisco Olarte <folarte@peoplecall.com> wrote:
> On Wed, Apr 11, 2018 at 11:17 AM, Dibyendu Majumdar
> <mobile@majumdar.org.uk> wrote:
>> 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++.
>
Sure, but that is the library developer's responsibility. If an API
existed to allow a library to set memory size associated with userdata
that would be a building block for libraries to inform the GC.
Sometimes this info may be approximate or the library may not be able
to provide it, but even so this is better than the current situation
where the GC is oblivious of the actual size of userdata objects.
Note that I am talking of fulluserdata objects here which are managed by GC.
The workaround I have used is to force full GC every so often which
defeats the idea of incremental GC.
Regards
Dibyendu