[Haskell-cafe] bytestring vs. uvector
Duncan Coutts
duncan.coutts at worc.ox.ac.uk
Sat Mar 14 11:48:04 EDT 2009
On Fri, 2009-03-13 at 20:30 +0300, Bulat Ziganshin wrote:
> Hello Don,
>
> Friday, March 13, 2009, 8:08:57 PM, you wrote:
>
> >> What is the reason why you have decided to use unpinned arrays
> >> (ByteArray#) instead of pinned arrays (Foreign.Ptr)?
>
> > They prevent heap fragmentation (and in general are faster).
>
> you probably mean faster alloc/gc operations, everything else should
> be the same
Right. Access times are the same. Both are just pointers internally. It
is just the allocation time, GC time and extra memory use and lower
cache utilisation caused by heap fragmentation.
For big arrays it doesn't make much difference. Big ByteArray#
allocations get pinned anyway. For small ones, like strings I expect the
difference is much more noticeable, though I have not measured it.
Using ByteArray# also means we can use ST/runST rather than
IO/unsafePerformIO. In general we should prefer heap allocated byte
arrays and ST unless we really really want to always use pinned
allocations to interact with C libs easily.
Duncan
More information about the Haskell-Cafe
mailing list