#ifdef __HUGS__
, FinalizerEnvPtr
#endif
+ -- ** Basic operations
, newForeignPtr
, newForeignPtr_
, addForeignPtrFinalizer
, addForeignPtrFinalizerEnv
#endif
, withForeignPtr
+
+ -- ** Low-level operations
, unsafeForeignPtrToPtr
, touchForeignPtr
, castForeignPtr
+ -- ** Allocating managed memory
, mallocForeignPtr
, mallocForeignPtrBytes
, mallocForeignPtrArray
mallocForeignPtrBytes n = do
r <- mallocBytes n
newForeignPtr finalizerFree r
-#endif /* __HUGS__ || __NHC__ */
+#endif /* !__GLASGOW_HASKELL__ */
+-- | This function is similar to 'Foreign.Marshal.Array.mallocArray',
+-- but yields a memory area that has a finalizer attached that releases
+-- the memory area. As with 'mallocForeignPtr', it is not guaranteed that
+-- the block of memory was allocated by 'Foreign.Marshal.Alloc.malloc'.
mallocForeignPtrArray :: Storable a => Int -> IO (ForeignPtr a)
mallocForeignPtrArray = doMalloc undefined
where
doMalloc :: Storable a => a -> Int -> IO (ForeignPtr a)
doMalloc dummy size = mallocForeignPtrBytes (size * sizeOf dummy)
+-- | This function is similar to 'Foreign.Marshal.Array.mallocArray0',
+-- but yields a memory area that has a finalizer attached that releases
+-- the memory area. As with 'mallocForeignPtr', it is not guaranteed that
+-- the block of memory was allocated by 'Foreign.Marshal.Alloc.malloc'.
mallocForeignPtrArray0 :: Storable a => Int -> IO (ForeignPtr a)
mallocForeignPtrArray0 size = mallocForeignPtrArray (size + 1)
return fObj
mallocForeignPtr :: Storable a => IO (ForeignPtr a)
--- ^ allocates some memory and returns a ForeignPtr to it. The memory
--- will be released automatically when the ForeignPtr is discarded.
+-- ^ Allocate some memory and return a 'ForeignPtr' to it. The memory
+-- will be released automatically when the 'ForeignPtr' is discarded.
--
--- @mallocForeignPtr@ is equivalent to
+-- 'mallocForeignPtr' is equivalent to
--
--- > do { p <- malloc; newForeignPtr p free }
+-- > do { p <- malloc; newForeignPtr finalizerFree p }
--
--- although it may be implemented differently internally. You may not
+-- although it may be implemented differently internally: you may not
-- assume that the memory returned by 'mallocForeignPtr' has been
--- allocated with C's @malloc()@.
+-- allocated with 'Foreign.Marshal.Alloc.malloc'.
mallocForeignPtr = doMalloc undefined
where doMalloc :: Storable a => a -> IO (ForeignPtr a)
doMalloc a = do
}
where (I# size) = sizeOf a
--- | similar to 'mallocForeignPtr', except that the size of the memory required
--- is given explicitly as a number of bytes.
+-- | This function is similar to 'mallocForeignPtr', except that the
+-- size of the memory required is given explicitly as a number of bytes.
mallocForeignPtrBytes :: Int -> IO (ForeignPtr a)
mallocForeignPtrBytes (I# size) = do
r <- newIORef []