RE: Making FFI callbacks call free() automatically when it's collected

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 20 Jul 2012 05:03:06 +0000

In my case I was passing string values between threads, as part of script body. 
 Using strings or numbers, probably both are fairly efficient.

 

By "size", I meant 32 and 64-bit aware.  If you just cast to 'int', I'm not 
sure you'll always get a unique key.

 

-- William



===============================
- Shaping clay is easier than digging it out of the ground.
http://williamaadams.wordpress.com
https://github.com/Wiladams



----------------------------------------
> Date: Fri, 20 Jul 2012 12:57:28 +0800
> Subject: Re: Making FFI callbacks call free() automatically when it's 
> collected
> From: arch.jslin@xxxxxxxxx
> To: luajit@xxxxxxxxxxxxx
>
> 2012/7/20 William Adams <william_a_adams@xxxxxxx>:
> >
> > I did the pointer thing like the following, to try and be somewhat size 
> > conscious:
> >
> >
> >
> >
> > function PointerToString(instance)
> > if ffi.abi("64bit") then
> > return string.format("0x%016x", tonumber(ffi.cast("int64_t", ffi.cast("void 
> > *", instance))))
> > elseif ffi.abi("32bit") then
> > return string.format("0x%08x", tonumber(ffi.cast("int32_t", ffi.cast("void 
> > *", instance))))
> > end
> >
> > return nil
> > end
> >
> >
>
> Hello, thanks for the snippet. :)
>
> It might be better to write that in this way:
>
> local pointer_conv
> if ffi.abi(xxx) then
> pointer_conv = function ... end
> elseif ffi.abi(ooo) then
> pointer_conv = function ... end
> end
>
> to make it a little bit more "compile-time thingy."
>
> I am also not sure about the need of converting to strings, for using
> it in the table keys. Does this have any advantages over using Lua
> numbers as keys?
>
> best,
> Johnson
>                                         

Other related posts: