regional-pointers-0.7: Regional memory pointers

MaintainerBas van Dijk <v.dijk.bas@gmail.com>

Foreign.Marshal.Alloc.Region

Contents

Description

 

Synopsis

Local allocation

data LocalPtr α r Source

A regional pointer to memory which was locally allocated by one of the alloca-like functions.

Note that a LocalPtr can not be duplicated to a parent region.

Instances

AllocatedPointer LocalPtr 
PrivateAllocatedPointer LocalPtr 
Pointer LocalPtr 

alloca :: (Storable α, RegionControlIO pr) => (forall sl. LocalPtr α (LocalRegion sl s) -> RegionT (Local s) pr β) -> RegionT s pr βSource

alloca f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory sufficient to hold values of type α.

The memory is freed when f terminates (either normally or via an exception).

This should provide a safer replacement for: Foreign.Marshal.Alloc.alloca.

allocaBytes :: RegionControlIO pr => Int -> (forall sl. LocalPtr α (LocalRegion sl s) -> RegionT (Local s) pr β) -> RegionT s pr βSource

allocaBytes n f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory of n bytes. The block of memory is sufficiently aligned for any of the basic foreign types that fits into a memory block of the allocated size.

The memory is freed when f terminates (either normally or via an exception).

This should provide a safer replacement for: Foreign.Marshal.Alloc.allocaBytes.

allocaBytesAligned :: RegionControlIO pr => Int -> Int -> (forall sl. LocalPtr α (LocalRegion sl s) -> RegionT (Local s) pr β) -> RegionT s pr βSource

This should provide a safer replacement for: Foreign.Marshal.Alloc.allocaBytesAligned.

Dynamic allocation

malloc :: forall α pr s. (Storable α, RegionControlIO pr) => RegionT s pr (RegionalPtr α (RegionT s pr))Source

Allocate a block of memory that is sufficient to hold values of type α.

Note that: malloc = mallocBytes $ sizeOf (undefined :: α)

This should provide a safer replacement for: Foreign.Marshal.Alloc.malloc.

mallocBytes :: RegionControlIO pr => Int -> RegionT s pr (RegionalPtr α (RegionT s pr))Source

Allocate a block of memory of the given number of bytes. The block of memory is sufficiently aligned for any of the basic foreign types that fits into a memory block of the allocated size.

This should provide a safer replacement for: Foreign.Marshal.Alloc.mallocBytes.