[Haskell-cafe] Fun with ByteStrings [was: A very edgy language]

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun Jul 8 11:30:33 EDT 2007


Hello Andrew,

Sunday, July 8, 2007, 7:16:46 PM, you wrote:
>>> [Char] is a linked list of pointers to heap-allocated fullword
>>> integers, 20 (40) bytes per character (assuming non-latin1).
>>>     
>>
>> Hey, I love ByteStrings!  ;-)
>>

actually only 12 (24 for 64-but cpu) as far as you use latin-1 chars.
the same should be true for [word8] but it's better to ask Simon

OTOH, using GC makes memory usage 3x larger. in those practical C
compression algorithms, memory is controlled manually. so, you have
36x space overhead. now you may guess how i decreased memory usage
12-fold :)

> If only there were a way to write functions that transparently work on
> both [x] and ByteString...

use pack/unpack to convert between them - it's cheap compared to your
algorithms

> Anyone have any comments on how ByteString is different from, say,
> UArray Word8?

mainly, algorithms implemented. the only technical difference is that
UArray uses ByteArray# and ByteString uses PinnedByteArray#, which has
different behavior in GC

-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list