Copyright | (c) Alexey Kuleshevich 2020 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <alexey@kuleshevi.ch> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data StablePtr a = StablePtr (StablePtr# a)
- newStablePtr :: MonadPrim RW m => a -> m (StablePtr a)
- deRefStablePtr :: MonadPrim RW m => StablePtr a -> m a
- freeStablePtr :: MonadPrim RW m => StablePtr a -> m ()
- castStablePtrToPtr :: StablePtr a -> Ptr ()
- castPtrToStablePtr :: Ptr () -> StablePtr a
Documentation
A stable pointer is a reference to a Haskell expression that is guaranteed not to be affected by garbage collection, i.e., it will neither be deallocated nor will the value of the stable pointer itself change during garbage collection (ordinary references may be relocated during garbage collection). Consequently, stable pointers can be passed to foreign code, which can treat it as an opaque reference to a Haskell value.
A value of type StablePtr a
is a stable pointer to a Haskell
expression of type a
.
StablePtr (StablePtr# a) |
Instances
newStablePtr :: MonadPrim RW m => a -> m (StablePtr a) Source #
Same as newStablePtr
, but generalized to MonadPrim
deRefStablePtr :: MonadPrim RW m => StablePtr a -> m a Source #
Same as deRefStablePtr
, but generalized to MonadPrim
freeStablePtr :: MonadPrim RW m => StablePtr a -> m () Source #
Same as freeStablePtr
, but generalized to MonadPrim
castStablePtrToPtr :: StablePtr a -> Ptr () #
Coerce a stable pointer to an address. No guarantees are made about
the resulting value, except that the original stable pointer can be
recovered by castPtrToStablePtr
. In particular, the address may not
refer to an accessible memory location and any attempt to pass it to
the member functions of the class Storable
leads to
undefined behaviour.
castPtrToStablePtr :: Ptr () -> StablePtr a #
The inverse of castStablePtrToPtr
, i.e., we have the identity
sp == castPtrToStablePtr (castStablePtrToPtr sp)
for any stable pointer sp
on which freeStablePtr
has
not been executed yet. Moreover, castPtrToStablePtr
may
only be applied to pointers that have been produced by
castStablePtrToPtr
.