lua-users home
lua-l archive

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





----- Ursprüngliche Message -----
> Von: Choonster TheMage <choonster.2010@gmail.com>
> An: Leo Romanoff <romixlev@yahoo.com>; Lua mailing list <lua-l@lists.lua.org>
> CC: 
> Gesendet: 19:26 Mittwoch, 24.Juli 2013
> Betreff: Re: Some questions and proposals about GC and memory management in Lua
> 
> On 25 July 2013 03:08, Leo Romanoff <romixlev@yahoo.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:
> http://www.lua.org/manual/5.1/manual.html#lua_Alloc
> http://www.lua.org/manual/5.2/manual.html#lua_Alloc


Thanks! I overlooked it. I can see now that it is possible to provide your custom memory allocation functions for lua states. 

-Leo