lua-users home
lua-l archive

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

2009/12/19 Javier Guerra <>:
> On Fri, Dec 18, 2009 at 5:06 PM, Francesco Abbate <> wrote:
>> I was thinking that it would be nice if the userdata could store one
>> or more reference to other userdata objects in order to ensure that
>> the GC does not free the main object that own the resource if other
>> objects that need the same resource are still alive.
> wouldn't it be much lighter to add a refcount field to your C data?
> increment when you add a Lua userdata, decrement on __gc, dispose if
> reaches zero.

this is what I've done but it forced me to add a stupid

unsigned ref_count

on all my C++ classes with a couple of ref and unref methods. Ideally
I would have liked to not touch the beautiful structures of my C++
classes and let Lua GC be aware of the cross-references.

For the other side I agree that it is the most efficient solution.