1 {-# LANGUAGE ForeignFunctionInterface #-}
2 module Mate.GarbageAlloc(
10 mallocStringUnmanaged) where
19 -- unified place for allocating Memory
20 -- TODO: implement GC stuff ;-)
22 mallocClassData :: Int -> IO (Ptr a)
23 mallocClassData size = do
24 printfStr $ printf "mallocClassData: %d\n" size
25 mem <- mallocBytes size
26 addRootGC mem (plusPtr mem size)
29 mallocStringGC :: Int -> IO (Ptr a)
30 mallocStringGC size = do
31 printfStr $ printf "mallocString: %d\n" size
34 foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff
35 mallocObjectGC :: Int -> IO CPtrdiff
36 mallocObjectGC size = do
37 ptr <- mallocBytesGC size
38 printfStr $ printf "mallocObject: %d\n" size
39 return $ fromIntegral $ ptrToIntPtr ptr
41 mallocObjectUnmanaged :: Int -> IO CPtrdiff
42 mallocObjectUnmanaged size = do
43 ptr <- mallocBytes size
44 printfStr $ printf "mallocObjectUnmanged: %d\n" size
45 return $ fromIntegral $ ptrToIntPtr ptr
47 mallocStringUnmanaged :: Int -> IO (Ptr a)
48 mallocStringUnmanaged size = do
49 printfStr $ printf "mallocStringUnamaged: %d\n" size
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"