Nevertheless, I think even without the tricks I'm using in GHC, the
case where a ForeignPtr is used in conjunction with malloc()/free()
is one which is likely to be optimisable in any system with its own
memory management.
I wasn't meaning so much that only GHC could take advantage of it
[...] using a ForeignPtr here, with free() as its finalizer, adds so
much overhead that [...]
Where is the overhead coming from? Is it the cost of a C call or the
cost of the standard malloc library?
It's the combined cost of
- malloc()
- creating a weak pointer to register the
1) Add these functions:
makeForeignPtr
:: Ptr a - FunPtr (Ptr a - IO ()) - IO (ForeignPtr a)
attachForeignPtrFinalizer
:: ForeignPtr a - FunPtr (Ptr a - IO ()) - IO ()
It is implementation defined whether the free functions are allowed
to call