Allocate some memory and return a
ForeignPtr to it. The memory
will be released automatically when the
ForeignPtr is
discarded.
mallocForeignPtr is equivalent to
do { p <- malloc; newForeignPtr finalizerFree p }
although it may be implemented differently internally: you may not
assume that the memory returned by
mallocForeignPtr has been
allocated with
malloc.
GHC notes:
mallocForeignPtr has a heavily optimised
implementation in GHC. It uses pinned memory in the garbage collected
heap, so the
ForeignPtr does not require a finalizer to free
the memory. Use of
mallocForeignPtr and associated functions is
strongly recommended in preference to
newForeignPtr with a
finalizer.