Re: Performance of ffi.new v/s malloc() arrays

  • From: Javier Guerra Giraldez <javier@xxxxxxxxxxx>
  • To: LuaJIT <luajit@xxxxxxxxxxxxx>
  • Date: Mon, 20 Feb 2017 08:50:57 +0000

On 20 February 2017 at 02:13, Ammar Hakim <a.hakim777@xxxxxxxxx> wrote:

   fieldInp = ffi.gc(ffi.cast("double*", ffi.C.calloc(nelem,
ffi.sizeof("double"))), ffi.C.free)


You have three different calls there, not only the allocator itself
(calloc), but also ffi.cast, which is a kind of allocator itself, and
finally ffi.gc (which mostly repeats what ffi.new does and calloc
doesn't).

try to define a specific ctype with a metatype table with the
deallocator, and declare your calloc as returning that type, i guess
you'll be able to avoid the ffi.cast, and the ffi.gc would come free.

-- 
Javier

Other related posts: