Advertisement
Tritonio

luajit double array allocation

May 16th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.35 KB | None | 0 0
  1. local ffi = require("ffi")
  2.  
  3. ffi.cdef[[
  4. void *malloc(size_t size);
  5. void free(void *ptr);
  6. ]]
  7.  
  8. local N = 2^32
  9. local arr = ffi.cast("double *", ffi.C.malloc(N*ffi.sizeof("double")))
  10. assert(arr ~= nil, "out of memory")
  11.  
  12. print("array =", arr)
  13. arr[0] = 1.5
  14. arr[N-1] = 2.5
  15. print("arr[0] =", arr[0])
  16. print("arr["..(N-1).."] =", arr[N-1])
  17.  
  18. ffi.C.free(arr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement