[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Some questions and proposals about GC and memory management in Lua
- From: Choonster TheMage <choonster.2010@...>
- Date: Thu, 25 Jul 2013 03:26:49 +1000
On 25 July 2013 03:08, Leo Romanoff <email@example.com> wrote:
> Based on these arguments, I'd like to discuss the following proposals:
> 1) Ability to define memory management functions per Lua-state (or even per object type, per metatable)
> For example, one could set custom malloc/calloc/free callbacks. By default, they would refer to what is used today. But one could provide custom implementaions, e.g. based on memory areans or region-based approach. BTW, if I remember correctly, LuaPlus allows something like this already. And the required changes are minimal. It is just about adding a few pointers to the LuaState structure.
I'm far from an expert on the C API or C in general, but isn't this
already possible by opening your states with lua_newstate instead of
luaL_newstate? The former lets you set your own allocator function
(and an opaque pointer to pass to it with each call), the latter uses
its own allocator function based on the standard realloc function.
The manual explains this in more detail: