1 {-# LANGUAGE ForeignFunctionInterface #-}
4 module Mate.GarbageAlloc(
22 -- unified place for allocating Memory
23 -- TODO: implement GC stuff ;-)
25 mallocClassData :: Int -> IO (Ptr a)
26 mallocClassData size = do
27 printfStr "mallocClassData: %d\n" size
28 mem <- mallocBytes size
29 addRootGC mem (plusPtr mem size)
32 mallocString :: Int -> IO (Ptr a)
33 mallocString size = do
34 printfStr "mallocString: %d\n" size
37 mallocStringVM :: Int -> IO (Ptr a)
38 mallocStringVM = mallocBytes
40 foreign export ccall mallocObject :: Int -> IO CPtrdiff
41 mallocObject :: Int -> IO CPtrdiff
42 mallocObject size = do
43 ptr <- mallocBytesGC size
44 printfStr "mallocObject: %d\n" size
45 return $ fromIntegral $ ptrToIntPtr ptr
47 mallocObjectVM :: Int -> IO CPtrdiff
48 mallocObjectVM size = do
49 ptr <- mallocBytes size
50 printfStr "mallocObject VM: %d\n" size
51 return $ fromIntegral $ ptrToIntPtr ptr
53 getHeapMemory :: IO Int
54 getHeapMemory = getHeapSizeGC
56 foreign export ccall printMemoryUsage :: IO ()
57 printMemoryUsage :: IO ()
58 printMemoryUsage = getHeapMemory >>= print
60 foreign export ccall printGCStats :: IO ()
62 printGCStats = putStrLn "Should print GC Stats"