data ForeignPtr a |
The ForeignPtr is parameterised in the same way as Ptr. The type argument of ForeignPtr should normally be an instance of class Storable.
instance Eq (ForeignPtr a) |
instance Ord (ForeignPtr a) |
instance Show (ForeignPtr a) |
type FinalizerPtr a = FunPtr (Ptr a -> IO ()) |
type FinalizerEnvPtr env a = FunPtr (Ptr env -> Ptr a -> IO ()) |
newForeignPtr :: FinalizerPtr a -> Ptr a -> IO (ForeignPtr a) |
newForeignPtr_ :: Ptr a -> IO (ForeignPtr a) |
addForeignPtrFinalizer :: FinalizerPtr a -> ForeignPtr a -> IO () |
newForeignPtrEnv :: FinalizerEnvPtr env a |
-> Ptr env -> Ptr a -> IO (ForeignPtr a) |
addForeignPtrFinalizerEnv :: FinalizerEnvPtr env a |
-> Ptr env -> ForeignPtr a -> IO () |
withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b |
This function is normally used for marshalling data to or from the object pointed to by the ForeignPtr, using the operations from the Storable class.
finalizeForeignPtr :: ForeignPtr a -> IO () |
unsafeForeignPtrToPtr :: ForeignPtr a -> Ptr a |
To avoid subtle coding errors, hand written marshalling code should preferably use Foreign.ForeignPtr.withForeignPtr rather than combinations of unsafeForeignPtrToPtr and touchForeignPtr. However, the latter routines are occasionally preferred in tool generated marshalling code.
touchForeignPtr :: ForeignPtr a -> IO () |
Note that this function should not be used to express dependencies between finalizers on ForeignPtrs. For example, if the finalizer for a ForeignPtrF1 calls touchForeignPtr on a second ForeignPtrF2, then the only guarantee is that the finalizer for F2 is never started before the finalizer for F1. They might be started together if for example both F1 and F2 are otherwise unreachable.
In general, it is not recommended to use finalizers on separate objects with ordering constraints between them. To express the ordering robustly requires explicit synchronisation between finalizers.
castForeignPtr :: ForeignPtr a -> ForeignPtr b |
mallocForeignPtr :: Storable a => IO (ForeignPtr a) |
mallocForeignPtr is equivalent to
although it may be implemented differently internally: you may not assume that the memory returned by mallocForeignPtr has been allocated with Foreign.Marshal.Alloc.malloc.
mallocForeignPtrBytes :: Int -> IO (ForeignPtr a) |
mallocForeignPtrArray :: Storable a => Int -> IO (ForeignPtr a) |
mallocForeignPtrArray0 :: Storable a => Int -> IO (ForeignPtr a) |