lua-users home
lua-l archive

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


On 23 March 2012 14:12, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> 1) Is it worth to pre-allocate a lua_State pool instead of creating it
> every time ?

You gain a little time by avoiding to reload all libraries each time
but you'll probably have to worry about the user script leaving garbage
behind or changing or deleting library functions. So I'd say create a
new Lua state every time unless that proves to be too time consuming.


I once toyed with the idea of having a low priority thread in my C program that would work during idle time to populate a container of lua_State instances, preloaded with everything they needed.

When a user request came in, a lua_State could be retrieved from this container and used straight away.

I guess you could have a similar pool-and-worker-thread model for destroying the states when they're finished with.