import Foreign.ForeignPtr import Foreign.Ptr import Foreign.Marshal import Control.Monad bufsize = 4096 -- or 2^20 bufcount = 10^4 -- and 50, correspondingly main = m 1 m i = do fptr <- mallocForeignPtrBytes bufsize withForeignPtr fptr $ \ptr -> do copyBytes ptr (ptr `plusPtr` 1) (bufsize-1) when (i==bufcount) $ do putStrLn$ show(bufcount*bufsize)++" bytes allocated" getLine return () m (i+1)