[Haskell-cafe] Difficult memory leak in array processing
niko.korhonen at gmail.com
Mon Nov 27 07:34:50 EST 2006
I can say neither that I have any idea what an 'undead array' is nor
that I would really understand the code you've posted. On the positive
side of things, you've given me a lot to think about. Maybe in the
fullness of time I shall return and say 'Lo! I can write leakless
Haskell code!'. But alas, that time seems so distant now.
However, this necromancy business really does sound like an exiting new
career prospect. Interesting job opportunities, respect of the
community, flexible hours and extremely loyal peers and other
commandlings that will literally work for just for the Brain Food.
Nik The Blak, Necromancer of the Glorious Forces of Evil
PSS: And I shall.
> Ah, yet another UndeadArray necromancer exhausting his stack of bones.
> May the forces of light suggest to structure the incantation of darkness?
> modifyArray arr i f =
> readArray arr i >>= \y -> writeArray arr i (f y)
> accumM :: (MArray a e m, Ix i) =>
> (e -> e' -> e) -> a i e -> [(i, e')] -> m ()
> accumM f arr xs = mapM_ chg xs
> where chg (i,x) = modifyArray arr i (flip f x)
> twodice (x:x':xs) = (x+x') `div` 2 : twodice xs
> noise rng gen = twodice $ randomRs rng gen
> main = do
> let bnds = (0, 10000000)
> buf <- newArray_ bnds :: IO Buffer
> gen <- getStdGen
> accumM (curry snd) buf $ zip (range bnds) $ noise (2,12) gen
> I absolutely don't know why there is no (accumM) function in the
> standard libraries. And having the ByteString API (maybe even the
> fusion) for general arrays would be very nice. Maybe (modifyArray) is
> missing, too.
> PS: did you try
> worker low (i `seq` i-1) ?
> PSS: The strictness analyzer is likely to insert that automatically if
> you compile with -O or -O2.
More information about the Haskell-Cafe