base-4.7.0.0: Basic libraries

Copyright(c) The FFI task force 2001
LicenseBSD-style (see the file libraries/base/LICENSE)
Maintainerffi@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

Foreign.Marshal.Array

Contents

Description

Marshalling support: routines allocating, storing, and retrieving Haskell lists that are represented as arrays in the foreign language

Synopsis

Marshalling arrays

Allocation

mallocArrayStorable a ⇒ IntIO (Ptr a) Source

Allocate storage for the given number of elements of a storable type (like malloc, but for multiple elements).

mallocArray0Storable a ⇒ IntIO (Ptr a) Source

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

allocaArrayStorable a ⇒ Int → (Ptr a → IO b) → IO b Source

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

allocaArray0Storable a ⇒ Int → (Ptr a → IO b) → IO b Source

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

reallocArrayStorable a ⇒ Ptr a → IntIO (Ptr a) Source

Adjust the size of an array

reallocArray0Storable a ⇒ Ptr a → IntIO (Ptr a) Source

Adjust the size of an array including an extra position for the end marker.

Marshalling

peekArrayStorable a ⇒ IntPtr a → IO [a] Source

Convert an array of given length into a Haskell list. The implementation is tail-recursive and so uses constant stack space.

peekArray0 ∷ (Storable a, Eq a) ⇒ a → Ptr a → IO [a] Source

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

pokeArrayStorable a ⇒ Ptr a → [a] → IO () Source

Write the list elements consecutive into memory

pokeArray0Storable a ⇒ a → Ptr a → [a] → IO () Source

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

Combined allocation and marshalling

newArrayStorable a ⇒ [a] → IO (Ptr a) Source

Write a list of storable elements into a newly allocated, consecutive sequence of storable values (like new, but for multiple elements).

newArray0Storable a ⇒ a → [a] → IO (Ptr a) 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

withArrayStorable a ⇒ [a] → (Ptr a → IO b) → IO b Source

Temporarily store a list of storable values in memory (like with, but for multiple elements).

withArray0Storable a ⇒ a → [a] → (Ptr a → IO b) → IO b Source

Like withArray, but a terminator indicates where the array ends

withArrayLenStorable a ⇒ [a] → (IntPtr a → IO b) → IO b Source

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

withArrayLen0Storable a ⇒ a → [a] → (IntPtr a → IO b) → IO b Source

Like withArrayLen, but a terminator indicates where the array ends

Copying

(argument order: destination, source)

copyArrayStorable a ⇒ Ptr a → Ptr a → IntIO () Source

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

moveArrayStorable a ⇒ Ptr a → Ptr a → IntIO () Source

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

Finding the length

lengthArray0 ∷ (Storable a, Eq a) ⇒ a → Ptr a → IO Int Source

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

Indexing

advancePtrStorable a ⇒ Ptr a → IntPtr a Source

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