[Haskell-cafe] [Haskell] ANNOUNCE: vector-bytestring-0.0.0.0
Bas van Dijk
v.dijk.bas at gmail.com
Fri Oct 14 14:24:50 CEST 2011
On 14 October 2011 14:01, Ertugrul Soeylemez <es at ertes.de> wrote:
> Is there any particular reason to prefer storable vectors instead of
> unboxed vectors? The element type is fixed to Word8 anyway.
To be able to safely interface with foreign libraries.
Note that unboxed vectors are represented as ByteArray#s. These are
"unpinned" which means that the GC can freely move them through the
heap to defragment your memory. If a foreign library had a pointer to
an unboxed vector and the GC would move the memory to some place else,
your program could crash. Storable vectors use a ForeignPtr instead
which (according how you allocated it) points to "pinned" memory.
You might like to follow the just created:
which proposes the pin# and unpin# primitives for dynamically pinning
and unpinning ByteArray#s. This way, as pumpkin explains it, you don't
have to decide up front whether you want to suffer from memory
fragmentation or to support foreign bindings.
It would be really nice if that could be implemented!
More information about the Haskell-Cafe