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

  • From: Johnson Lin <arch.jslin@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 20 Jul 2012 21:36:10 +0800

2012/7/20 Mike Pall <mike-1207@xxxxxxxxxx>:
> Robert G. Jakabosky wrote:
>> I would use a cast to uintptr_t instead of int to support 64bit pointers.
>> uintptr_t is guaranteed to be the same size as a pointer.
> Use intptr_t if you plan to pass it to tonumber().
> Conversions between *unsigned* integers and FP numbers are rather
> expensive on some platforms. Most CPUs only support conversions of
> *signed* integers to/from FP numbers.
> Anyway, the only supported 64 bit platform is x64 (and only if it
> uses the lower 47 bits of the address space for user mode). I.e.
> all 64 bit pointer values are non-negative and the 47 significant
> bits fit into the mantissa of a double.
> Do NOT use tostring() to get unique keys for simple scalar cdata
> objects (it's not JIT-compiled, too).
> --Mike

Thanks again for the guidelines, I'll adjust accrodingly.

As a side note, after reading this:
and related links in the page...

I am more and more convinced that it is not worth the effort. I'll
still try some simplified kind of "scope" thing, it only has to fit my
current needs, but if I can't get that done I think then manual
management is still the only sensible way to go.

Other game engines like CoronaSDK, which binds Lua to C/C++ codebases
have this problem too. An image object in Corona has to call
obj:removeSelf() to really remove its image/texture from the engine,
you just cannot rely on GC / finalizers for that in a straightforward
way. I think it just happens, whenever Lua has access to outside


Other related posts: