any alternative to ffi.string for reading from ByteData ?
Posted: Thu Dec 02, 2021 6:39 pm
Is there any way to read from an allocated love ByteData object besides using ffi.string ( or a trivial c library imported with ffi.load )?
e.g.
Motivated by three things: 1) avoiding string interning of millions of temporary strings, 2) avoiding the garbage collector, 3) working with very large, contiguous arrays of (32-bit unsigned) integers.
e.g.
Code: Select all
local mem = love.data.newByteData(2 ^ 31) -- 2 GB
local ptr = ffi.cast('uint8_t*', mem:getFFIPointer()) -- PVOID
local testkey = '0123456789ABCDE'
local length = #testkey
ffi.copy(ptr,testkey,length)
ffi.copy(ptr + length,testkey,length)
local whole = ffi.string(ptr,length*2)
print(whole)
local index = 3
local out = ffi.string(ptr+index,1)
print(out)