[Haskell-beginners] Re: Space leak in a fold even after the usual
fixes
Daniel Fischer
daniel.is.fischer at web.de
Mon Apr 12 14:09:38 EDT 2010
Am Montag 12 April 2010 19:11:21 schrieb Travis Erdman:
> > I take it that size of the array does not depend on arg ?
> >
> > Apparently, despite your attempts to force evaluation, the array still
> > contains many unevaluated expressions. Documentation for the vector
> > pacakge reveals that Data.Vector is a *boxed* array, i.e. the
> > entries are only evaluated on demand, so that's where the unevaluated
> > expressions linger around.
> >
> > Unless you need the extra laziness - which you probably don't, given
> > how you've structured your algorithm - you might want to switch to
> > Data.Vector.Unboxed or Data.Vector.Storable.
>
> Correct. The array size doesn't depend on arg (arg only controls how
> much of the input list to process.
>
> I did not realize that the boxed arrays would have this extra-lazy
> behavior. The reason I chose boxed is because I needed to store these
> very large trees (custom data type) that I referenced in an earlier
> question. Since D.V.Unboxed and Storable don't appear to support
> non-standard data types, is there another package that might better fit
> my needs?
You could try to introduce the necessary strictness via Control.DeepSeq
and/or Control.Parallel.Strategies, strictly writing (newTree `using` rnf)
to the array.
> Data.IntMap perhaps? I originally chose an array over a map
> because I need fast random access to individual elements (and cheap
> modification).
>
> Thanks again,
>
> Travis Erdman
More information about the Beginners
mailing list