Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |
---|
- module Control.Monad.Trans.Region
- data RegionalPtr α r
- nullPtr :: NullPtr α RootRegion
- data NullPtr α r
- class Pointer pointer where
- mapPointer :: (Ptr α -> Ptr β) -> pointer α r -> pointer β r
- class PrivateAllocatedPointer pointer => AllocatedPointer pointer
- castPtr :: Pointer pointer => pointer α r -> pointer β r
- alignPtr :: AllocatedPointer pointer => pointer α r -> Int -> pointer α r
- plusPtr :: AllocatedPointer pointer => pointer α r -> Int -> pointer β r
- minusPtr :: AllocatedPointer pointer => pointer α r1 -> pointer β r2 -> Int
Documentation
Note that this module re-exports the Control.Monad.Trans.Region
module
from the regions
package which allows you to run regions using runRegionT
and duplicate a RegionalPtr
to a parent region using dup
.
module Control.Monad.Trans.Region
Regional pointers
data RegionalPtr α r Source
A regional pointer to memory.
This should provide a safer replacement for Foreign.Ptr.
Ptr
AllocatedPointer RegionalPtr | |
PrivateAllocatedPointer RegionalPtr | |
Pointer RegionalPtr | |
MaybePeek RegionalPtr | |
Dup (RegionalPtr α) |
Null pointers
nullPtr :: NullPtr α RootRegionSource
The constant nullPtr
is a pointer which is not associated with a valid
memory location.
Note that nullPtr
is a pure value. This means it does not perform the
side-effect of registering a finalizer like "free nullPtr
"
in the RegionT
monad.
Finally note that the region parameter of the NullPtr
is set to
RootRegion
which is the ancestor of any region.
This allows nullPtr
to be used in any region.
Class of pointers
class Pointer pointer whereSource
mapPointer :: (Ptr α -> Ptr β) -> pointer α r -> pointer β rSource
Apply a pure function to the inner pointer of a regional pointer.
class PrivateAllocatedPointer pointer => AllocatedPointer pointer Source
Pure functions on pointers
castPtr :: Pointer pointer => pointer α r -> pointer β rSource
The castPtr
function casts a pointer from one type to another.
Wraps: Foreign.Ptr.
castPtr
alignPtr :: AllocatedPointer pointer => pointer α r -> Int -> pointer α rSource
Given an arbitrary address and an alignment constraint, alignPtr
yields
the next higher address that fulfills the alignment constraint. An alignment
constraint x
is fulfilled by any address divisible by x
. This operation
is idempotent.
Wraps: Foreign.Ptr.
alignPtr
plusPtr :: AllocatedPointer pointer => pointer α r -> Int -> pointer β rSource
Advances the given address by the given offset in bytes.
Wraps: Foreign.Ptr.
plusPtr
minusPtr :: AllocatedPointer pointer => pointer α r1 -> pointer β r2 -> IntSource
Computes the offset required to get from the second to the first argument. We have
p2 == p1 `plusPtr` (p2 `minusPtr` p1)
Wraps: Foreign.Ptr.
minusPtr