HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulebase-compat-0.14.1Haskell2010

Foreign.Marshal.Compat

  • 1 type
  • 64 values
valuevoid :: IO a -> IO ()
#

Deprecated. use void instead

Discard the return value of an IO action

newtypenewtype Pool
#

A memory pool.

valuefillBytes :: Ptr a -> Word8 -> Int -> IO ()
#

Fill a given number of bytes in memory area with a byte value.

valuenew :: Storable a => a -> IO (Ptr a)
#

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.

The memory may be deallocated using free or finalizerFree when no longer required.

valuealloca :: Storable a => (Ptr a -> IO b) -> IO b
#

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

The memory is freed when f terminates (either normally or via an exception), so the pointer passed to f must not be used after this.

valueallocaBytes :: Int -> (Ptr a -> IO b) -> IO b
#

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), so the pointer passed to f must not be used after this.

valueallocaBytesAligned :: Int -> Int -> (Ptr a -> IO b) -> IO b
#

allocaBytesAligned size align f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory of size bytes and aligned to align bytes. The value of align must be a power of two.

The memory is freed when f terminates (either normally or via an exception), so the pointer passed to f must not be used after this.

valuemalloc :: Storable a => IO (Ptr a)
#

Allocate a block of memory that is sufficient to hold values of type a. The size of the area allocated is determined by the sizeOf method from the instance of Storable for the appropriate type.

The memory may be deallocated using free or finalizerFree when no longer required.

valuemallocBytes :: Int -> IO (Ptr a)
#

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.

The memory may be deallocated using free or finalizerFree when no longer required.

valuerealloc :: Storable b => Ptr a -> IO (Ptr b)
#

Resize a memory area that was allocated with malloc or mallocBytes to the size needed to store values of type b. The returned pointer may refer to an entirely different memory area, but will be suitably aligned to hold values of type b. The contents of the referenced memory area will be the same as of the original pointer up to the minimum of the original size and the size of values of type b.

If the argument to realloc is nullPtr, realloc behaves like malloc.

valuereallocBytes :: Ptr a -> Int -> IO (Ptr a)
#

Resize a memory area that was allocated with malloc or mallocBytes to the given size. The returned pointer may refer to an entirely different memory area, but will be sufficiently aligned for any of the basic foreign types that fits into a memory block of the given size. The contents of the referenced memory area will be the same as of the original pointer up to the minimum of the original size and the given size.

If the pointer argument to reallocBytes is nullPtr, reallocBytes behaves like malloc. If the requested size is 0, reallocBytes behaves like free.

valuecopyArray :: Storable a => Ptr a -> Ptr a -> Int -> IO ()
#

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

valuemoveArray :: Storable a => Ptr a -> Ptr a -> Int -> IO ()
#

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

valuenewArray :: Storable a => [a] -> IO (Ptr a)
#

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

valuenewArray0 :: Storable a => a -> [a] -> IO (Ptr a)
#

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

valuepeekArray :: Storable a => Int -> Ptr a -> IO [a]
#

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

valuepeekArray0 :: (Storable a, Eq a) => a -> Ptr a -> IO [a]
#

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

valuepokeArray0 :: Storable a => a -> Ptr a -> [a] -> IO ()
#

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

valuewithArray :: Storable a => [a] -> (Ptr a -> IO b) -> IO b
#

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

valuecopyBytes
  1. :: Ptr a

    Destination

  2. -> Ptr a

    Source

  3. -> Int

    Size in bytes

  4. -> IO ()
#

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

valuemoveBytes
  1. :: Ptr a

    Destination

  2. -> Ptr a

    Source

  3. -> Int

    Size in bytes

  4. -> IO ()
#

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

valuetoBool :: (Eq a, Num a) => a -> Bool
#

Convert a Boolean in numeric representation to a Haskell value

valuewith :: Storable a => a -> (Ptr a -> IO b) -> IO b
#

with val f executes the computation f, passing as argument a 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), so the pointer passed to f must not be used after this.

valuewithMany :: (a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res
#

Replicates a withXXX combinator over a list of objects, yielding a list of marshalled objects

valuethrowIf
  1. :: (a -> Bool)

    error condition on the result of the IO action

  2. -> (a -> String)

    computes an error message from erroneous results of the IO action

  3. -> IO a

    the IO action to be executed

  4. -> IO a
#

Execute an IO action, throwing a userError if the predicate yields True when applied to the result returned by the IO action. If no exception is raised, return the result of the computation.

valuefreePool :: Pool -> IO ()
#

Deallocate a memory pool and everything which has been allocated in the pool itself.

valuepooledMalloc :: Storable a => Pool -> IO (Ptr a)
#

Allocate space for storable type in the given pool. The size of the area allocated is determined by the sizeOf method from the instance of Storable for the appropriate type.

valuepooledMallocArray0 :: Storable a => Pool -> Int -> IO (Ptr a)
#

Allocate storage for the given number of elements of a storable type in the pool, but leave room for an extra element to signal the end of the array.

valuepooledNew :: Storable a => Pool -> a -> IO (Ptr a)
#

Allocate storage for a value in the given pool and marshal the value into this storage.

valuepooledNewArray :: Storable a => Pool -> [a] -> IO (Ptr a)
#

Allocate consecutive storage for a list of values in the given pool and marshal these values into it.

valuepooledNewArray0 :: Storable a => Pool -> a -> [a] -> IO (Ptr a)
#

Allocate consecutive storage for a list of values in the given pool and marshal these values into it, terminating the end with the given marker.

valuepooledReallocBytes :: Pool -> Ptr a -> Int -> IO (Ptr a)
#

Adjust the storage area for an element in the pool to the given size. Note that the previously allocated space is still retained in the same Pool and will only be freed when the entire Pool is freed.

valuewithPool :: (Pool -> IO b) -> IO b
#

Execute an action with a fresh memory pool, which gets automatically deallocated (including its contents) after the action has finished.