[Haskell-cafe] FPS lib

Simon Marlow simonmar at microsoft.com
Tue Oct 18 07:20:46 EDT 2005

On 18 October 2005 10:08, Krasimir Angelov wrote:

> I am curious why FPS is implemented on top of ForeignPtr. ByteArray#
> based implementation should be faster and more space efficient.

Actually there's not much difference between ForeignPtr and ByteArray#,
at least in GHC 6.5+ where we optimised the ForeignPtr implementation.  

Furthermore ForeignPtr is much more useful, because you can create a
ForeignPtr from a Ptr, and you can pass a ForeignPtr to C code portably
(i.e. not using GHC extensions).  ForeignPtr is essential if you want to
make packed strings from eg. mmap()'d memory.  

Also, a ForeignPtr allocated using mallocForeignPtr *is* a ByteArray#.

My PackedString library (which DonS is currently merging with FPS) uses
ForeignPtr and gets pretty good performance.  withForeignPtr compiles to
almost nothing at all: the touch# becomes visible to GHC and compiles to
no code.  I needed to inline unsafePerformIO to get the best results,
though (not always safe, but in this case it's ok).


More information about the Haskell-Cafe mailing list