lua-users home
lua-l archive

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


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?

Thanks,
Olav Wölfelschneider