On 64-bit platforms, LuaJIT allows only up to 1-2GB of data (not counting objects allocated with malloc
). Where does this limitation come from, and why is this even less than on 32-bit platforms?
相关问题
- How to get the return code of a shell script in lu
- Accessing Light userdata in Lua
- Wireshark dissector that works with tls/ssl
- Email address validation using corona sdk
- Using a coordinate pair as a key in a Lua table
相关文章
- Lua Integer type
- First character uppercase Lua
- torch / lua: retrieving n-best subset from Tensor
- How to handle errors when resuming a Lua thread (c
- Is Lua an object-oriented language?
- Getting previous day's date in Lua
- How do I create a save game feature in love2d?
- What is the best way for debug output for the lua
LuaJIT is designed to use 32-bit pointers. On
x64
platforms the limit comes from the use of mmap and theMAP_32BIT
flag.Essentially using this flag limits to the first 31-bits, not the first 32-bits as the name suggests. Have a look here for a nice overview of the 1GB limit using
MAP_32BIT
in the Linux kernel.Even if you could have more than 1GB, the LuaJIT author explains why this would be bad for performance:
To summarize, the 1GB limit is a limitation of the Linux kernel and the LuaJIT garbage collector. This only applies to objects within the LuaJIT state and can be overcome by using
malloc
, which will allocate outside the lower 32-bit address space. Also, it's possible to use thex86
build onx64
in 32-bit mode and have access the full 4GB.Check out these links for more information:
Due to recent patch luajit 2GB memory limit can be solved.
To test, clone this repo and build with
LUAJIT_ENABLE_GC64
symbol defined:or
XCFLAGS+= -DLUAJIT_ENABLE_GC64
inMakefile
I used this code to test memory allocation:
Allocated 48GB before
not enough memory
error on my machine.