lua-users home
lua-l archive

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


On Saturday 06, Stefan Reich wrote:
> 
> Robert G. Jakabosky wrote:
> > For limiting memory usage I would recommend my Emergency GC patch:
> > http://lua-users.org/wiki/EmergencyGarbageCollector
> > 
> > Using just a custom allocator (without EGC support) will not allows
> > scripts to run reliably when they get close to the limit.
> 
> I see. I am currently not focused on the memory issue, but it's good
> to know that solutions are available when we want to get airtight
> there. Is your GC really stable? I see there is a stress test. Does it
> pass? :D

Yes it is stable, there are no outstanding bugs.  It is currently being used 
by the eLua project [1].

> Also, how does limiting memory for coroutines work with your GC? I
> couldn't find an example. Is it done from within Lua?

With how the Lua vm was designed there is no way to have per-coroutine memory 
limits in the same Lua State (I mean the main lua_State instance, not the 
lua_State's you get from lua_newthread).

I would recommend using separate lua_State's (created from 
lua_newstate/luaL_newstate) for each script.

To set the memory limit from C:
lua_gc(L, LUA_GCSETMEMLIMIT, 2 * 1024); /* 2Mbyte limit */

From Lua:
collectgarbage("setmemlimit", 2 * 1024) -- 2Mbyte limit

Set the limit to 0 (the default value) to disable the limit.

1. http://www.eluaproject.net/
-- 
Robert G. Jakabosky