[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Using Lua's memory allocator
- From: Artur Galyamov <artur-pub@...>
- Date: Tue, 11 Oct 2011 18:04:07 +0400
> If I grab some memory using lua_newuserdata, and after using that memory
> for the above-mentioned operations simply throw away the pointer to it
> (i.e. never push it on the Lua stack), then that memory will be reclaimed
> - have I got that right?
First, to use automatic stack management, i.e. to have dedicated stack frame, all your functions should be "Lua C functions" (see lua_CFunction) and be called from Lua or using lua_call() etc. Big work here. Otherwise, you can only use initial Lua stack, where *you* must lua_pop() chunks, because first frame never returns. Not very useful too, better stay with malloc/free.
Second, lua_newuserdata() creates and pushes(!) new userdata on stack. If you lua_pop() it, it may be immediately reclaimed.
If you just need gc for C, use native (Boehm).
But read , it is still unknown.
Anyway, leave internal allocations to malloc/free, and only allocate exported objects with lua_newuserdata().
Never store result of lua_touserdata() to permanent places, and you are fine.