[Haskell-cafe] Copying Arrays
Don Stewart
dons at galois.com
Thu May 29 16:27:13 EDT 2008
duncan.coutts:
>
> 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
> prototype).
>
> 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.
There are these guys,
foreign import ccall unsafe "__hscore_memcpy_dst_off"
memcpy_baoff_ba :: RawBuffer -> CInt -> RawBuffer -> CSize -> IO (Ptr ())
foreign import ccall unsafe "__hscore_memcpy_dst_off"
memcpy_baoff_ptr :: RawBuffer -> CInt -> Ptr a -> CSize -> IO (Ptr ())
type RawBuffer = MutableByteArray# RealWorld
More information about the Haskell-Cafe
mailing list