Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LuaJit increase stack/heap size

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

Thanks

like image 371
jameszhao00 Avatar asked May 11 '26 08:05

jameszhao00


1 Answers

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.

like image 147
RBerteig Avatar answered May 14 '26 09:05

RBerteig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!