lua-users home
lua-l archive

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


>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.
--lhf