[Haskell-cafe] Re: Space Leak Help

Anatoly Zaretsky anatoly.zaretsky at gmail.com
Sun Feb 4 08:19:18 EST 2007


On 2/4/07, Dominic Steinitz <dominic.steinitz at blueyonder.co.uk> wrote:
> pad causes a stack overflow and pad1 uses up about 6m of heap.
>
> pad = pad' 0
>   where pad' l [] = [0x80] ++ ps
>           where pl = (64-(l+9)) `mod` 64
>                 ps = replicate pl 0x00
>         pad' l (x:xs) = x : pad' (l+1) xs

pad = pad' 0
  where pad' l [] = [0x80] ++ ps
          where pl = (64-(l+9)) `mod` 64
                ps = replicate pl 0x00
        pad' l (x:xs) = x : (pad' $! l+1) xs -- otherwise (l+1) it
will be deferred until replicate

--
Tolik


More information about the Haskell-Cafe mailing list