HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-internal-9.1003.0Haskell2010

GHC.Internal.Foreign.Marshal.Pool

This module contains support for pooled memory management. Under this scheme, (re-)allocations belong to a given pool, and everything in a pool is deallocated when the pool itself is deallocated. This is useful when alloca with its implicit allocation and deallocation is not flexible enough, but explicit uses of malloc and free are too awkward.

  • 1 type
  • 14 values

Pool management

4 declarations
newtypenewtype Pool
#

A memory pool.

valuefreePool :: Pool -> IO ()
#

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

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.

(Re-)Allocation within a pool

8 declarations
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.

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.

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.

Combined allocation and marshalling

3 declarations
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.