Why is LuaJIT's memory limited to 1-2 GB on 64-bit platforms?

前端 未结 2 2052
失恋的感觉
失恋的感觉 2021-01-12 13:02

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

2条回答
  •  梦谈多话
    2021-01-12 13:53

    Due to recent patch luajit 2GB memory limit can be solved.

    To test, clone this repo and build with LUAJIT_ENABLE_GC64 symbol defined:

    msvcbuild.bat gc64
    

    or XCFLAGS+= -DLUAJIT_ENABLE_GC64 in Makefile

    I used this code to test memory allocation:

    local ffi = require("ffi")
    
    local CHUNK_SIZE     = 1 * 1024 * 1024 * 1024
    local fraction_of_gb = CHUNK_SIZE / (1024*1024*1024)
    local allocations    = {}
    
    for index=1, 64 do
        local huge_memory_chunk = ffi.new("char[?]", CHUNK_SIZE)
        table.insert(allocations, huge_memory_chunk)
        print( string.format("allocated %q GB", index*fraction_of_gb) )
        local pause = io.read(1)
    end
    
    print("Test complete")
    local pause = io.read(1)
    

    Allocated 48GB before not enough memory error on my machine.

提交回复
热议问题