[Haskell-cafe] Blitting one IOUArray into another
denbuen at sandia.gov
Wed Jan 7 11:56:19 EST 2009
Oh, do you mean by actually calling memcpy via ffi?
From: Don Stewart [dons at galois.com]
Sent: Wednesday, January 07, 2009 9:23 AM
To: Bulat Ziganshin
Cc: Bueno, Denis; haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] Blitting one IOUArray into another
You can of course memcpy unboxed arrays fairly easily.
> Hello Denis,
> Wednesday, January 7, 2009, 6:56:36 PM, you wrote:
> memory allocated for i :)))
> each new copy of i needs one word. the situation was much worse with
> Int64, of course :)
> > 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
> Best regards,
> Bulat mailto:Bulat.Ziganshin at gmail.com
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe