1 {-# LANGUAGE ForeignFunctionInterface #-}
4 module Mate.GarbageAlloc(
11 mallocObjectUnmanaged,
12 mallocStringUnmanaged) where
24 -- unified place for allocating Memory
25 -- TODO: implement GC stuff ;-)
27 mallocClassData :: Int -> IO (Ptr a)
28 mallocClassData size = do
29 printfStr "mallocClassData: %d\n" size
30 mem <- mallocBytes size
31 addRootGC mem (plusPtr mem size)
34 mallocStringGC :: Int -> IO (Ptr a)
35 mallocStringGC size = do
36 printfStr "mallocString: %d\n" size
39 foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff
40 mallocObjectGC :: Int -> IO CPtrdiff
41 mallocObjectGC size = do
42 ptr <- mallocBytesGC size
43 printfStr "mallocObject: %d\n" size
44 return $ fromIntegral $ ptrToIntPtr ptr
46 mallocObjectUnmanaged :: Int -> IO CPtrdiff
47 mallocObjectUnmanaged size = do
48 ptr <- mallocBytes size
49 printfStr "mallocObjectUnmanged: %d\n" size
50 return $ fromIntegral $ ptrToIntPtr ptr
52 mallocStringUnmanaged :: Int -> IO (Ptr a)
53 mallocStringUnmanaged size = do
54 printfStr "mallocStringUnamaged: %d\n" size
58 getHeapMemory :: IO Int
59 getHeapMemory = getHeapSizeGC
61 foreign export ccall printMemoryUsage :: IO ()
62 printMemoryUsage :: IO ()
63 printMemoryUsage = getHeapMemory >>= print
65 foreign export ccall printGCStats :: IO ()
67 printGCStats = putStrLn "Should print GC Stats"