
Hello Simon, Thursday, April 20, 2006, 1:23:42 PM, you wrote:
it's possible to write lib so it will use any unboxed array and this will work both with ForeignPtr and ByteArray# implementations
- 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.
Simon, you skipped the whole idea - the lib should work with any array, including StorableArray too. it should be just Array->ListLike interface converter, with additional code specialized for unmovable arrays. plus UTF-8 support at the top of this: module ArrayToListLike class ListLike head tail ... instance (Array a e) => ListLike (a e) module UTF8PackedString import ArrayToListLike newtype UTF8PackedString = UTF8PackedString (UArray Int Word8) instance ListLike UTF8PackedString well, i'm not sure that this can be implemented with classes. but at least this can be implemented with preprocessor (that is Haskell's module system ;) just like yourself implemented packed strings for 1/2/4-byte wide representations. here, array type and array elements type will be parameters: #define ARRAY UArray #define ELEMENT Word8 #include "Str.hs" #define ARRAY StorableArray #define ELEMENT Word8 #include "Str.hs"
Optimising the library for GHC 6.4.x isn't a goal (for me, at least).
1. i think that we will have really stable release of 6.6 at Fall'2007, not earlier 2. ForeignPtr has the following drawbacks even for 6.6: - need more memory. main goal of using packed string is to reduce memory requirements so adding 10-15 bytes is bad idea - can point only to the unmovable memory blocks that may increase overall memory consumption for some apps. general Array can work with any memory - movable heap, unmovable heap, or C-allocated -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com