[Haskell-cafe] Unboxed arrays

Jed Brown jed at 59A2.org
Wed Mar 26 12:02:28 EDT 2008

On Wed 2008-03-26 14:22, Henning Thielemann wrote:
> A light-weight unboxed array variant is:
>   http://code.haskell.org/~sjanssen/storablevector/

There is also CArray which offers an immutable interface for any Storable.


You can also do unsafe (no-copy) freeze/thaw to IOCArray which is equivalent to
StorableArray.  Unfortunately there is a performance hit to using Storable
versus the built in unboxed types.  On the other hand, CArray is binary
compatible with C which is handy if you are making foreign calls.

> I thought it might be more efficient sometimes to split, say Word8 and 
> Double data into two arrays, instead of padding data in order to align a 
> (Word8,Double) record, but this wouldn't fit into the array data structure.

This depends on the access pattern, but if it makes you miss the cache
frequently, then it is certainly not the way to go.  For split storage to win,
you must frequently traverse while only referencing one entry.  It is not clear
(to me) how to make an interface where the split storage is hidden, but the
compiler can still remove all references to the unused part (without boxing
which defeats the purpose).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080326/07073fb3/attachment.bin

More information about the Haskell-Cafe mailing list