GHC.Prim.ByteArray# - confusing documentation
Antoine Latter
aslatter at gmail.com
Thu Dec 24 18:18:36 EST 2009
Folks,
I found some of the documentation in GHC.Prim confusing - so I thought
I'd share. The documentation for the ByteArray# type[1] explains
that's it's a raw region in memory that also remembers it's size.
Consequently I expected sizeOfByteArray# to return the same number
that I passed in to newByteArray#. But it doesn't - It returned
however much it decided to allocate, which on my platform is always a
multiple of four bytes.
This is something which could be clarified in the documentation.
So it turns out I need to carry my own length around in something like
(Int, ByteArray#).
(I tested all of this with the primitive[2] package, which is a thin
wrapper around GHC.Prim)
Antoine
1: http://hackage.haskell.org/packages/archive/ghc-prim/0.1.0.0/doc/html/GHC-Prim.html#t%3AByteArray%23
2: http://hackage.haskell.org/package/primitive
More information about the Glasgow-haskell-users
mailing list