[Haskell] ANNOUNCE: FPS - FastPackedStrings 0.2

Simon Marlow simonmarhaskell at gmail.com
Thu Apr 20 05:23:42 EDT 2006

Donald Bruce Stewart wrote:
> bulat.ziganshin:

>>2. it uses ForeignPtr, that is slow in ghc 6.4 and require more
>>memory than ByteArray# in any ghc version. in addition, you place two
>>Ints here. it's question of taste, of course - whether we want to have
>>better speed or memory requirements. i personally prefer to have
>>minimal memory overhead that will be accomplished by using ByteArray#
>>plus one Int to hold string's size. it's possible to write lib so it
>>will use any unboxed array and this will work both with ForeignPtr
>>and ByteArray# implementations. It will also allow to implement
>>general list-like interface for any immutable arrays what should be
>>useful, in particular for collections framework that is now written by
>>JP Bernardy. of course, using general Array instead of ForeignPtr will
>>make some functions (such as mmap) unimplementable for common case
> That's quite a big change. I'd like to see a prototype first, and some
> numbers. As SPJ sometimes says: "show me the code".

Optimising the library for GHC 6.4.x isn't a goal (for me, at least). 
I'm convinced that ForeignPtr is the right choice.  No other 
representation can give you all of these:

   - converting arbitrary Ptrs into PackedStrings without copying,
     including finalizers if necessary (useful for mmap()).

   - garbage-collectable PackedStrings can be allocated on the heap, no
     finalizer necessary

   - PackedStrings can be passed to foreign functions without copying

ByteArray# only gives you the second two.  You would need two variants 
of the representation to get all three, and that means extra overhead.


More information about the Libraries mailing list