--- /dev/null
+Name: hs-boehmgc
+Version: 0.1
+Synopsis: none
+Description: Haskell bindings for Boehm-Demers-Weiser conservative GC used in MateVM
+License: GPL-3
+Author: Harald Steinlechner, Bernhard Urban
+Maintainer: Harald Steinlechner <haraldsteinlechner@gmail.com>
+Build-Depends: base
+cabal-version: >= 1.2
+build-type: Simple
+
+library
+ build-depends: base
+ exposed-modules: Mate.GC.Boehm
+ hs-source-dirs: src
--- /dev/null
+{-# LANGUAGE CPP #-}
+module Mate.GC.Boehm (
+ mallocBytesGC,
+ unsafeFreeGC,
+ getHeapSize,
+ ) where
+
+#define DEBUG
+
+import Foreign.Marshal.Alloc
+import Foreign.Ptr
+import Data.IORef
+import System.IO.Unsafe
+
+-- counts allocated memory in heap
+{-# NOINLINE globalBytesAllocated #-}
+globalBytesAllocated :: IORef Int
+globalBytesAllocated = unsafePerformIO (newIORef 0)
+
+#ifdef DEBUG
+-- |Allocates size bytes in managed memory
+mallocBytesGC :: Int -> IO (Ptr a)
+mallocBytesGC size = modifyIORef globalBytesAllocated (+ size) >> mallocBytes size
+#else
+-- |Allocates size bytes in managed memory
+mallocBytesGC :: Int -> IO (Ptr a)
+mallocBytesGC = mallocBytes
+#endif
+
+-- |Explicitely deallocate an object. Not required and dangerous.
+unsafeFreeGC :: Ptr a -> IO ()
+unsafeFreeGC _ = print "not implemented"
+
+-- |Returns currently allocated memory in bytes
+getHeapSize :: IO Int
+getHeapSize = readIORef globalBytesAllocated