[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Garbage collector issues
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 20 Dec 2000 00:43:02 -0200 (EDT)
>need a way to tell Lua how much memory it's using on your userdata
Lua 4.0 contains an undocumented function that does this and more:
LUA_API void *lua_newuserdata (lua_State *L, size_t size);
lua_newuserdata allocates a buffer of the given size and returns it to the
user untouched, much like malloc, except that it uses Lua's internal malloc,
and that the udata is added to the pool and GC is called on it; moreover it
does take "size" into account for triggering GC.
lua_newuserdata is in lua.h, so I think it will remain there...
Note that the udata created by lua_newuserdata has no references inside Lua
at birth, and so you have to set it to a global variable or a table field,
or something; otherwise it will be collected next time.