1 {-# LANGUAGE ForeignFunctionInterface #-}
4 module Mate.GarbageAlloc(
21 -- unified place for allocating Memory
22 -- TODO: implement GC stuff ;-)
24 mallocClassData :: Int -> IO (Ptr a)
25 mallocClassData size = do
26 printfStr "mallocClassData: %d\n" size
27 mem <- mallocBytes size
28 addRootGC mem (plusPtr mem size)
31 mallocString :: Int -> IO (Ptr a)
32 mallocString size = do
33 printfStr "mallocString: %d\n" size
36 mallocStringVM :: Int -> IO (Ptr a)
37 mallocStringVM = mallocBytes
39 foreign export ccall mallocObject :: Int -> IO CPtrdiff
40 mallocObject :: Int -> IO CPtrdiff
41 mallocObject size = do
42 ptr <- mallocBytesGC size
43 printfStr "mallocObject: %d\n" size
44 return $ fromIntegral $ ptrToIntPtr ptr
46 mallocObjectVM :: Int -> IO CPtrdiff
47 mallocObjectVM size = do
48 ptr <- mallocBytes size
49 printfStr "mallocObject VM: %d\n" size
50 return $ fromIntegral $ ptrToIntPtr ptr
53 foreign export ccall demoInterfaceCall :: CUInt -> IO ()
54 demoInterfaceCall :: CUInt -> IO ()
55 demoInterfaceCall val = do
56 printf "demoInterfaceCall: 0x%08x\n" (fromIntegral val :: Word32)
59 getHeapMemory :: IO Int
60 getHeapMemory = getHeapSizeGC
63 foreign export ccall printMemoryUsage :: IO ()
64 printMemoryUsage :: IO ()
65 printMemoryUsage = getHeapMemory >>= print