[Haskell-cafe] Copying Arrays

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu May 29 12:49:46 EDT 2008


Hello Tom,

Thursday, May 29, 2008, 8:21:25 PM, you wrote:

> Are there any low-level array types (MutableByteArray#, for example)
> that support a memcpy-like function

yes, MBA# allows to use memcpy. you can find examples of its
usage right in the array package, for example:

thawSTUArray :: Ix i => UArray i e -> ST s (STUArray s i e)
thawSTUArray (UArray l u arr#) = ST $ \s1# ->
    case sizeofByteArray# arr#          of { n# ->
    case newByteArray# n# s1#           of { (# s2#, marr# #) ->
    case unsafeCoerce# memcpy marr# arr# n# s2# of { (# s3#, () #) ->
    (# s3#, STUArray l u marr# #) }}}

foreign import ccall unsafe "memcpy"
    memcpy :: MutableByteArray# RealWorld -> ByteArray# -> Int# -> IO ()

i can give you further explanations if required

-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list