Copyright | (c) Sven Panne 2002-2004 |
---|---|
License | (c) Sven Panne 2002-2004 |
Maintainer | sven.panne@aedion.de |
Stability | provisional |
Portability | portable |
Safe Haskell | Trustworthy |
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.
- data Pool
- newPool :: IO Pool
- freePool :: Pool -> IO ()
- withPool :: (Pool -> IO b) -> IO b
- pooledMalloc :: Storable a => Pool -> IO (Ptr a)
- pooledMallocBytes :: Pool -> Int -> IO (Ptr a)
- pooledRealloc :: Storable a => Pool -> Ptr a -> IO (Ptr a)
- pooledReallocBytes :: Pool -> Ptr a -> Int -> IO (Ptr a)
- pooledMallocArray :: Storable a => Pool -> Int -> IO (Ptr a)
- pooledMallocArray0 :: Storable a => Pool -> Int -> IO (Ptr a)
- pooledReallocArray :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)
- pooledReallocArray0 :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)
- pooledNew :: Storable a => Pool -> a -> IO (Ptr a)
- pooledNewArray :: Storable a => Pool -> [a] -> IO (Ptr a)
- pooledNewArray0 :: Storable a => Pool -> a -> [a] -> IO (Ptr a)
Pool management
freePool :: Pool -> IO ()Source
Deallocate a memory pool and everything which has been allocated in the pool itself.
withPool :: (Pool -> IO b) -> IO bSource
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
pooledMallocBytes :: Pool -> Int -> IO (Ptr a)Source
Allocate the given number of bytes of storage in the pool.
pooledRealloc :: Storable a => Pool -> Ptr a -> IO (Ptr a)Source
Adjust the storage area for an element in the pool to the given size of the required type.
pooledReallocBytes :: Pool -> Ptr a -> Int -> IO (Ptr a)Source
Adjust the storage area for an element in the pool to the given size.
pooledMallocArray :: Storable a => Pool -> Int -> IO (Ptr a)Source
Allocate storage for the given number of elements of a storable type in the pool.
pooledMallocArray0 :: Storable a => Pool -> Int -> IO (Ptr a)Source
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.
pooledReallocArray :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)Source
Adjust the size of an array in the given pool.
pooledReallocArray0 :: Storable a => Pool -> Ptr a -> Int -> IO (Ptr a)Source
Adjust the size of an array with an end marker in the given pool.
Combined allocation and marshalling
pooledNew :: Storable a => Pool -> a -> IO (Ptr a)Source
Allocate storage for a value in the given pool and marshal the value into this storage.