[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Garbage collection vs. userdata
- From: "O. Wölfelschneider" <lua@...>
- Date: Thu, 04 Dec 2008 16:15:30 +0100
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.
However, if I allocate something using lua_newuserdata(), will the pointer be
constant over its lifetime?
I fear the GC might like to move userdata around in memory during sweeps?