1 {-# LANGUAGE ForeignFunctionInterface #-}
4 module Mate.GarbageAlloc(
11 mallocObjectUnmanaged,
12 mallocStringUnmanaged) where
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 mallocStringGC :: Int -> IO (Ptr a)
33 mallocStringGC size = do
34 printfStr "mallocString: %d\n" size
37 foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff
38 mallocObjectGC :: Int -> IO CPtrdiff
39 mallocObjectGC size = do
40 ptr <- mallocBytesGC size
41 printfStr "mallocObject: %d\n" size
42 return $ fromIntegral $ ptrToIntPtr ptr
44 mallocObjectUnmanaged :: Int -> IO CPtrdiff
45 mallocObjectUnmanaged size = do
46 ptr <- mallocBytes size
47 printfStr "mallocObjectUnmanged: %d\n" size
48 return $ fromIntegral $ ptrToIntPtr ptr
50 mallocStringUnmanaged :: Int -> IO (Ptr a)
51 mallocStringUnmanaged size = do
52 printfStr "mallocStringUnamaged: %d\n" size
56 getHeapMemory :: IO Int
57 getHeapMemory = getHeapSizeGC
59 foreign export ccall printMemoryUsage :: IO ()
60 printMemoryUsage :: IO ()
61 printMemoryUsage = getHeapMemory >>= print
63 foreign export ccall printGCStats :: IO ()
65 printGCStats = putStrLn "Should print GC Stats"