gc: factor out allocation
[mate.git] / Mate / GarbageAlloc.hs
diff --git a/Mate/GarbageAlloc.hs b/Mate/GarbageAlloc.hs
new file mode 100644 (file)
index 0000000..f5b1093
--- /dev/null
@@ -0,0 +1,19 @@
+module Mate.GarbageAlloc where
+
+import Foreign
+import Foreign.C
+
+-- unified place for allocating Memory
+-- TODO: implement GC stuff ;-)
+
+mallocClassData :: Int -> IO (Ptr a)
+mallocClassData = mallocBytes
+
+mallocString :: Int -> IO (Ptr a)
+mallocString = mallocBytes
+
+foreign export ccall mallocObject :: Int -> IO CUInt
+mallocObject :: Int -> IO CUInt
+mallocObject size = do
+  ptr <- mallocBytes size
+  return $ fromIntegral $ ptrToIntPtr ptr