debugging memory allocations
Simon Marlow
simonmar at microsoft.com
Wed Feb 2 12:01:43 EST 2005
On 02 February 2005 13:38, Duncan Coutts wrote:
> I'm looking for advice on how to figure out why some piece of code is
> allocating memory when I think it ought to be able to work in constant
> space.
>
> In these cases we cannot turn on traditional profiling since that
> would
> interfere with the optimisations we are relying on to eliminate most
> of
> the other memory allocations.
>
> Would looking at the core files help? What would I be looking for?
>
> Here's a simple version that I would expect to run in constance space.
>
> pixbufSetGreen :: Pixbuf -> IO ()
> pixbufSetGreen pixbuf = do
> ptr <- pixbufGetPixels pixbuf
> sequence_
> [ do pokeByteOff ptr (y*384+3*x) (0 ::Word8)
> pokeByteOff ptr (y*384+3*x+1) (128::Word8)
> pokeByteOff ptr (y*384+3*x+2) (96 ::Word8)
> | y <- [0..127]
> , x <- [0..127] ]
>
> (Don't worry about all those random constants, it's just test code!)
Yes, let's see the core. Since you're interested in allocation, you
might be better off with -ddump-prep rather than -ddump-simpl: the
former has all the allocation made into explicit 'let' expressions ready
for code generation.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list