[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Garbage collection vs. userdata
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Thu, 4 Dec 2008 17:03:32 +0100
2008/12/4 "O. Wölfelschneider" <email@example.com>:
> Jerome Vuarand wrote:
>> If you want Lua to manage the memory allocated by that library, you
>> can write a custom allocator that you would pass to that library. The
>> allocator would allocate the big chunk of memory as a Lua userdata.
>> That way the Lua garbage collector would be aware of it. You can then
>> tell the GC about the dependency between your small userdata (the one
>> you already have with just a pointer) and the big one (the memory
>> chunk) with environment tables.
> In that case I could just get rid of the indirection and put the library
> chunk directly into the userdata.
It can still be useful, for example if that kind of object can be part
of a bigger structure elsewhere, in such a case you would need to have
a pointer userdata to account for the relative offset. And using the
same access method in all cases (including when the pointer kind of
owns the object) can simplify the code.