27 Sep 20:05
lua_setallocf question
From: BrianL <__dart <at> yahoo.com>
Subject: lua_setallocf question
Newsgroups: gmane.comp.lang.lua.general
Date: 2008-09-27 18:06:19 GMT
Subject: lua_setallocf question
Newsgroups: gmane.comp.lang.lua.general
Date: 2008-09-27 18:06:19 GMT
This seems like a really basic question - I'm probably missing some documentation or
discussionsomewhere. If so, please point me at it as I couldn't find anything on this specific issue:
If I install a custom allocator as follow:
lua_State* state = luaL_newstate();
lua_setallocf(state, &CustomAllocator::lua_Alloc, &alloc);
lua_close(state);
...I get zero allocations (expected, as I do no work before destroying the state) but I get several
deallocations from allocations performed in luaL_newstate. This isn't safe given a custom allocator
that stores a header/footer for allocations, etc as it will cause memory corruption or memory leaks.
What is the correct way of handling this? I could restore the default allocator before calling
lua_closestate it seems like that would still have the same ambiguity issues (ie allocations performed
with the custom allocator could be freed to the default lua allocator).
Thank you!
RSS Feed