10 import Foreign.Marshal.Alloc
13 import System.IO.Unsafe
15 -- counts allocated memory in heap
16 {-# NOINLINE globalBytesAllocated #-}
17 globalBytesAllocated :: IORef Int
18 globalBytesAllocated = unsafePerformIO (newIORef 0)
21 -- |Allocates size bytes in managed memory
22 mallocBytesGC :: Int -> IO (Ptr a)
23 mallocBytesGC size = modifyIORef globalBytesAllocated (+ size) >> mallocBytes size
25 -- |Allocates size bytes in managed memory
26 mallocBytesGC :: Int -> IO (Ptr a)
27 mallocBytesGC = mallocBytes
30 -- |Explicitely deallocate an object. Not required and dangerous.
31 unsafeFreeGC :: Ptr a -> IO ()
32 unsafeFreeGC _ = print "not implemented"
34 -- |Returns currently allocated memory in bytes
36 getHeapSize = readIORef globalBytesAllocated