lua-users home
lua-l archive

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


I find your patch very useful for resource-constrained systems (read
"most of the medium power micros out there"). That said, I'd rather
take the patch in its previous form. That is, from a custom allocator
only. It seems to allow one to "fine tune" the whole allocation
process better. On the other hand, this is also possible with the
latest patch, which also allows one to control this behavior directly
from Lua, so this is fine with me. Very good work.

On Sat, May 10, 2008 at 5:04 AM, Robert G. Jakabosky
<bobby@sharedrealm.com> wrote:
> Updated patch attached 'emergency_gc-5.1.3.patch'.  Fixed the infinite loop
> bug and added memory limit support to the Lua core.
>
> This new patch removes the need for a custom allocator like the one used in my
> lua_memlimit program.
>
> Additions to C API:
> /* get current memlimit in Kbytes */
> int memlimit = lua_gc(L, LUA_GCGETMEMLIMIT, 0);
> /* set memlimit to 64Kbytes */
> lua_gc(L, LUA_GCSETMEMLIMIT, 64);
>
> Additions to Lua API:
> -- get current memlimit in Kbytes
> memlimit = collectgarbage("getmemlimit");
> -- set memlimt to 64Kbytes
> collectgarbage("setmemlimit", 64);
>
> If memlimit > 0, then the Lua core will do a step collection when the script
> tries to allocate more memory then the limit allows.  If the step collection
> finishes a full collection cycle and still can't free enough memory a "not
> enough memory" error will be thrown.
>
> If the allocator fails (returning NULL when nsize > 0) a full garbage
> collection cycle will be do and then the allocator will be tried one last
> time before throwing the "not enought memory" error.  Right now this can't be
> disabled by setting "memlimit" to 0.
>
> Trying to set memlimit to a value less then the currently allocated byte count
> will cause a full garbage collection.  if the allocated byte count is still
> larger then memlimit, then then new memlimit will be the allocated byte count
> rounded up to the next multiple of 1024.
>
> Also I added a '-m limit' option to the command line interpreter.
>
> To limit life.lua to 64Kbytes run this command:
> lua -m 64 life.lua
>
> On 64bit builds of Lua the life.lua script will atleast 85Kbytes.
>
> Any comments or suggestions about these changes are welcome.
>
> --
> Robert G. Jakabosky
>