+
+-- ToDo: use mallocBytes from PrelMarshal?
+malloc :: Int -> IO (Ptr ())
+malloc sz = do
+ a <- _malloc sz
+ if (a == nullPtr)
+ then ioException (IOError Nothing ResourceExhausted
+ "malloc" "out of memory" Nothing)
+ else return a
+
+foreign import "malloc" unsafe _malloc :: Int -> IO (Ptr ())