X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=Mate%2FGarbageAlloc.hs;h=c2b622c95f1b6f2f601cbcbbdb6cf3d90a583724;hb=ccc1ff2921984cfd36595e935e3634842fa2cb7d;hp=b0165d0b9453a3eef149ab1b2213659060e2a2ab;hpb=3eef04b9310493654f75ec7732420cbed7cd723c;p=mate.git diff --git a/Mate/GarbageAlloc.hs b/Mate/GarbageAlloc.hs index b0165d0..c2b622c 100644 --- a/Mate/GarbageAlloc.hs +++ b/Mate/GarbageAlloc.hs @@ -1,20 +1,65 @@ {-# LANGUAGE ForeignFunctionInterface #-} -module Mate.GarbageAlloc where +{-# LANGUAGE CPP #-} +#include "debug.h" +module Mate.GarbageAlloc( + mallocClassData, + mallocStringGC, + mallocObjectGC, + getHeapMemory, + printMemoryUsage, + printGCStats, + mallocObjectUnmanaged, + mallocStringUnmanaged) where import Foreign import Foreign.C +import Mate.GC.Boehm + +--import Text.Printf +import Mate.Debug + -- unified place for allocating Memory -- TODO: implement GC stuff ;-) mallocClassData :: Int -> IO (Ptr a) -mallocClassData = mallocBytes +mallocClassData size = do + printfStr "mallocClassData: %d\n" size + mem <- mallocBytes size + addRootGC mem (plusPtr mem size) + return mem -mallocString :: Int -> IO (Ptr a) -mallocString = mallocBytes +mallocStringGC :: Int -> IO (Ptr a) +mallocStringGC size = do + printfStr "mallocString: %d\n" size + mallocBytesGC size -foreign export ccall mallocObject :: Int -> IO CUInt -mallocObject :: Int -> IO CUInt -mallocObject size = do +foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff +mallocObjectGC :: Int -> IO CPtrdiff +mallocObjectGC size = do + ptr <- mallocBytesGC size + printfStr "mallocObject: %d\n" size + return $ fromIntegral $ ptrToIntPtr ptr + +mallocObjectUnmanaged :: Int -> IO CPtrdiff +mallocObjectUnmanaged size = do ptr <- mallocBytes size + printfStr "mallocObjectUnmanged: %d\n" size return $ fromIntegral $ ptrToIntPtr ptr + +mallocStringUnmanaged :: Int -> IO (Ptr a) +mallocStringUnmanaged size = do + printfStr "mallocStringUnamaged: %d\n" size + mallocBytes size + + +getHeapMemory :: IO Int +getHeapMemory = getHeapSizeGC + +foreign export ccall printMemoryUsage :: IO () +printMemoryUsage :: IO () +printMemoryUsage = getHeapMemory >>= print + +foreign export ccall printGCStats :: IO () +printGCStats :: IO () +printGCStats = putStrLn "Should print GC Stats"