views:

458

answers:

1

Hi,

I keep getting a out of memory error in LuaJit. How do I increase the stack or heap size?

Thanks

+3  A: 

I haven't used LuaJIT myself, other than with toy examples. But since noone else has provided any answers yet...

From skimming the documentation, LuaJIT depends on the Coco extensions to the standard coroutine library. One of the changes introduced by Coco is that the functions that create a new coroutine now take an optional argument that specifies the stack size.

Quoting the Coco docs:

coro = coroutine.create(f [, cstacksize])
func = coroutine.wrap(f [, cstacksize])

The optional argument cstacksize specifies the size of the C stack to allocate for the coroutine:

  • A default stack size is used if cstacksize is not given or is nil or zero.
  • No C stack is allocated if cstacksize is -1.
  • Any other value is rounded up to the minimum size (i.e. use 1 to get the minimum size).

There is also the new function coroutine.cstacksize([newdefault]) that sets the default C stack size, as well as some corresponding changes to the C API.

Furthermore, there are numerous compile-time configuration options in the LuaJIT version of luaconf.h. There may be something in there that sets the default. On Windows, there is also a link-time setting for the executable's basic stack, set by MSVC's LINK.EXE via the STACKSIZE statement in the application's .DEF file.

RBerteig
Thanks. I will try increasing the c compiler stack size and decreasing the coroutine stack size.
jameszhao00
No dice. I tried injecting -Wl,--stacksize= flags into the ldargs but it seems to be ignoring it.
jameszhao00
I'm not sure that *decreasing* the coroutine stack size will help. I had in mind *increasing* it... I didn't see any statement of what controls the stack size of the initial thread, if it isn't the link-time stack size. But if you have coroutines and it is one of them that is reporting out of stack, then you need to increase the stack size available to at least that coroutine if not all.
RBerteig
I thought there was a fixed per thread stack storage and each coroutine's simulated stack took a chunk of that. Thus decreasing the coroutine's simulated stack size should allow more coroutines to be created.
jameszhao00