regional-pointers-0.4: Regional memory pointers

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

Foreign.Marshal.Array.Region

Contents

Description

 

Synopsis

Allocation

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

Allocate storage for the given number of elements of a storable type.

Like malloc, but for multiple elements.

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

Like mallocArray, but add an extra position to hold a special termination element.

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

Temporarily allocate space for the given number of elements (like alloca, but for multiple elements).

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

Like allocaArray, but add an extra position to hold a special termination element.

TODO: Define and export reallocArray and reallocArray0

Marshalling

peekArray :: (Storable α, ParentOf pr cr, MonadIO cr) => Int -> RegionalPtr α pr -> cr [α]Source

Convert an array of given length into a Haskell list.

(This version traverses the array backwards using an accumulating parameter, which uses constant stack space. The previous version using mapM needed linear stack space.)

Wraps: Foreign.Marshal.Array.peekArray.

peekArray0 :: (Storable α, Eq α, ParentOf pr cr, MonadIO cr) => α -> RegionalPtr α pr -> cr [α]Source

Convert an array terminated by the given end marker into a Haskell list.

Wraps: Foreign.Marshal.Array.peekArray0.

pokeArray :: (Storable α, ParentOf pr cr, MonadIO cr) => RegionalPtr α pr -> [α] -> cr ()Source

Write the list elements consecutive into memory.

Wraps: Foreign.Marshal.Array.pokeArray.

pokeArray0 :: (Storable α, ParentOf pr cr, MonadIO cr) => α -> RegionalPtr α pr -> [α] -> cr ()Source

Write the list elements consecutive into memory and terminate them with the given marker element.

Wraps: Foreign.Marshal.Array.pokeArray0.

Combined allocation and marshalling

newArray :: (Storable α, MonadCatchIO pr) => [α] -> RegionT s pr (RegionalPtr α (RegionT s pr))Source

Write a list of storable elements into a newly allocated, consecutive sequence of storable values.

Like new, but for multiple elements.

newArray0 :: (Storable α, MonadCatchIO pr) => α -> [α] -> RegionT s pr (RegionalPtr α (RegionT s pr))Source

Write a list of storable elements into a newly allocated, consecutive sequence of storable values, where the end is fixed by the given end marker.

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

Temporarily store a list of storable values in memory.

Like with, but for multiple elements.

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

Like withArray, but a terminator indicates where the array ends.

withArrayLen :: (Storable α, MonadCatchIO pr) => [α] -> (forall s. Int -> RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr βSource

Like withArray, but the action gets the number of values as an additional parameter.

withArrayLen0 :: (Storable α, MonadCatchIO pr) => α -> [α] -> (forall s. Int -> RegionalPtr α (RegionT s pr) -> RegionT s pr β) -> pr βSource

Like withArrayLen, but a terminator indicates where the array ends.

Copying

copyArraySource

Arguments

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

Destination

-> RegionalPtr α pr2

Source

-> Int

Number of elements to copy.

-> cr () 

Copy the given number of elements from the second array (source) into the first array (destination); the copied areas may not overlap.

Wraps: Foreign.Marshal.Array.copyArray.

moveArraySource

Arguments

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

Destination

-> RegionalPtr α pr1

Source

-> Int

Number of elements to move.

-> cr () 

Copy the given number of elements from the second array (source) into the first array (destination); the copied areas may overlap.

Wraps: Foreign.Marshal.Array.moveArray.

Finding the length

lengthArray0 :: (Storable α, Eq α, ParentOf pr cr, MonadIO cr) => α -> RegionalPtr α pr -> cr IntSource

Return the number of elements in an array, excluding the terminator.

Wraps: Foreign.Marshal.Array.lengthArray0.

Indexing

advancePtr :: Storable α => RegionalPtr α pr -> Int -> RegionalPtr α prSource

Advance a pointer into an array by the given number of elements.

Wraps: Foreign.Marshal.Array.advancePtr.