lua-users home
lua-l archive

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


To address (2) you can also have a coroutine for each object and write your own coroutine scheduler that keeps track of the cpu time taken by each coroutine.

 Sat, 07 Jul 2007 20:39:10 -0500, Irayo <irayo.lt@irayo.net> escreveu:

> TongKe Xue wrote:
> >
> > ussing Ruby as my scripting language of choice.
> Might try mailing the Ruby list then... :P
> >
> >   (1) I need to be able to limit the memory usage of the object.
> >   (2) I need to be able to limit the CPU cycle usage of the object.
> >
> This can be done fairly simply.  Try a Google search for 'Lua sandbox'.  
> For a simple implementation, checking the os.clock(); function result in 
> a debug hook function will tell you how long a script has been running, 
> and then you can decide whether to terminate it.  
> collectgarbage("count") will tell you how much memory (in kilobytes) a 
> script is using.  In C, setting a memory alloc function will allow you 
> full control over memory and this would be better and more effective.  
> CPU is more difficult, but if you use threads (might check LuaTask, 
> LuaThreads, etc. but I don't have experience with these), then each 
> script will be given (roughly) equal processing time so it won't matter 
> too much anyway.
> 
> -- 
> Irayo
> 
> 
> 
>