[Haskell-cafe] Blitting one IOUArray into another

Bueno, Denis denbuen at sandia.gov
Wed Jan 7 10:56:36 EST 2009


Hi all,

I'm seeing a lot of unexpected memory allocation with some simple code that
copies the contents of one vector (IOUArray Int Int64) into another of the
same type and dimensions.  In particular, profiling reveals that `copyInto'
is allocating oodles and oodles of memory.

My small test case creates two 50000-element arrays and performs 10000
copies from one into the other.  Since the elements are Int64s and the
arrays are unboxed, each array should be

    50000 elements * 8 bytes per element = 400,000 bytes

and so the arrays should only take 800,000 bytes total.  I understand
there's some overhead for thunks and whatnot, but the profiler reported
allocation is around 40 billion bytes.  And almost all of that allocation is
in my copying function, not in main (main allocates the arrays).

I've attached two versions of the code, just for comparison.  The only
difference is the way the copying is done.  One calls `getBounds' to figure
out the bounds, and one is given the bounds for copying.  They're both about
the same speed and allocation (originally I was using IOUArray Int64 Int64,
and there was a much greater allocation difference between the two versions;
but that went away.  Oh well).

So, does anyone know why copying takes so much allocation?  I expect there
is _some_ way to just move memory from one array to another, like a memcpy
-- how can I do that?
                              Denis

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ArrayCopyGetBounds.hs
Type: application/octet-stream
Size: 815 bytes
Desc: ArrayCopyGetBounds.hs
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090107/09d377a9/ArrayCopyGetBounds.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arraycopygetbounds.prof
Type: application/octet-stream
Size: 1889 bytes
Desc: arraycopygetbounds.prof
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090107/09d377a9/arraycopygetbounds.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ArrayCopyWithBounds.hs
Type: application/octet-stream
Size: 807 bytes
Desc: ArrayCopyWithBounds.hs
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090107/09d377a9/ArrayCopyWithBounds.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arraycopywithbounds.prof
Type: application/octet-stream
Size: 1825 bytes
Desc: arraycopywithbounds.prof
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090107/09d377a9/arraycopywithbounds.obj


More information about the Haskell-Cafe mailing list