regional-pointers-0.2: Regional memory pointers

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

Foreign.Marshal.Utils.Region

Contents

Description

 

Synopsis

General marshalling utilities

Combined allocation and marshalling

with :: (Storable α, MonadCatchIO pr) => α -> (forall s. RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr βSource

with val f executes the computation f, passing as argument a regional pointer to a temporarily allocated block of memory into which val has been marshalled (the combination of alloca and poke).

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

This provides a safer replacement for Foreign.Marshal.Utils.with.

new :: (Storable α, MonadCatchIO pr) => α -> RegionT s pr (RegionalPtr α (RegionT s pr))Source

Allocate a block of memory and marshal a value into it (the combination of malloc and poke). The size of the area allocated is determined by the sizeOf method from the instance of Storable for the appropriate type.

This provides a safer replacement for Foreign.Marshal.Utils.new.

Marshalling of Boolean values (non-zero corresponds to True)

fromBool :: Num a => Bool -> a

Convert a Haskell Bool to its numeric representation

toBool :: Num a => a -> Bool

Convert a Boolean in numeric representation to a Haskell value

Marshalling of Maybe values

TODO: Define and export: maybeNew, maybeWith and maybePeek.

Marshalling lists of storable objects

TODO: Define and export: withMany.

Haskellish interface to memcpy and memmove

(argument order: destination, source)

copyBytesSource

Arguments

:: (ParentOf pr1 cr, ParentOf pr2 cr, MonadIO cr) 
=> RegionalPtr α pr1

Destination

-> RegionalPtr α pr2

Source

-> Int

Number of bytes to copy

-> cr () 

Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may not overlap

Wraps: Foreign.Marshal.Utils.copyBytes.

moveBytesSource

Arguments

:: (ParentOf pr1 cr, ParentOf pr2 cr, MonadIO cr) 
=> RegionalPtr α pr1

Destination

-> RegionalPtr α pr2

Source

-> Int

Number of bytes to move

-> cr () 

Copies the given number of bytes from the second area (source) into the first (destination); the copied areas may overlap

Wraps: Foreign.Marshal.Utils.moveBytes.