[Haskell-cafe] Copying Arrays

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Thu May 29 14:57:02 EDT 2008

On Thu, 2008-05-29 at 11:25 -0700, Bryan O'Sullivan wrote:
> Tom Harper wrote:
> > Because I'm writing the Unicode-friendly ByteString =p
> Perhaps I'm not understanding.  Why wouldn't you use ByteString for I/O,
> even if you're writing a different library?  After all, ByteString's own
> internals use memcpy.

Just to clarify Tom's question...

He's designing a proper Unicode type along the lines of ByteString.
However it does not use a ByteString underneath so we cannot re-use the
IO operations from ByteString, though obviously we can steal ideas.

The reason we do not want to re-use ByteString as the underlying
representation is because they're not good for short strings and we
expect that for Unicode text (more than arbitrary blobs of binary data)
people will want efficient short strings.

So instead of using a ForeignPtr to pinned heap memory (read: slow
allocation, lots of fragmentation) we're looking at using unpinned heap
arrays. So that means MutableByteArr# (or STUArray for the first

We cannot use memcpy because it operates on raw pointers but that's no
good for a movable heap object like a ByteArr#.

So that's the background to the question.

I think the answer is either that there's a primitive to do this copying
in the GHC.* libs or we'll need to add one.


More information about the Haskell-Cafe mailing list