[Haskell-cafe] Re: Space Leak Help

Claus Reinke claus.reinke at talk21.com
Sun Feb 4 08:02:33 EST 2007


> pad causes a stack overflow and pad1 uses up about 6m of heap.
> pad1 xs =
>   xs ++ [0x80] ++ ps
>   where
>      l = length xs
>      pl = (64-(l+9)) `mod` 64
>      ps = replicate pl 0x00

wild guess: if you compute the length when the consumer reaches ps,
you hold on to a copy of xs longer than needed, whereas if you compute 
the length upfront, you unfold xs too early.

the zip-trick you mentioned might work around this, allowing you to
consume xs lazily while still having its length at the end.

but if you're only interested in the **length modulo 64**, you should 
be able to process and let go of xs in chunks of length 64, too small
for overflows?

Claus


More information about the Haskell-Cafe mailing list