#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | sc_bufferDesc |
struct | sc_blockDesc |
struct | sc_blockAllocator |
A fixed size block allocator object. More... | |
Typedefs | |
typedef struct sc_bufferDesc | sc_bufferDesc |
typedef struct sc_blockDesc | sc_blockDesc |
Functions | |
sc_status | sc_blockAllocator_construct (sc_blockAllocator *pba, s_int32 blockSize, s_int32 initialCapacity, s_int32 maxCapacity) |
sc_status | sc_blockAllocator_destruct (sc_blockAllocator *pba) |
sc_status | sc_blockAllocator_allocate (sc_blockAllocator *pba, void **ppblock) |
sc_status | sc_blockAllocator_free (sc_blockAllocator *pba, void *pblock) |
An object that can allocate and deallocate fixed sized blocks in constant time. The storage (in blocks) can be fixed or growable at the caller's option.
sc_status sc_blockAllocator_allocate | ( | sc_blockAllocator * | pba, | |
void ** | ppblock | |||
) |
Allocates a single block. May grow the block pool if necessary, up to maxCapacity blocks.
[in,out] | pba | The allocator object to allocate from. |
[out] | ppblock | The allocated block returned at *ppblock. |
sc_status sc_blockAllocator_construct | ( | sc_blockAllocator * | pba, | |
s_int32 | blockSize, | |||
s_int32 | initialCapacity, | |||
s_int32 | maxCapacity | |||
) |
Constructs an allocator of initialCapacity blocks (growable up to maxCapacity), where each block contains blockSize bytes.
[in,out] | pba | The block allocator object to construct. |
[in] | blockSize | The size of each block in bytes. |
[in] | initialCapacity | The initial number of blocks to ready. |
[in] | maxCapacity | The max number of blocks to allocate. |
sc_status sc_blockAllocator_destruct | ( | sc_blockAllocator * | pba | ) |
Destructs the given block allocator.
sc_status sc_blockAllocator_free | ( | sc_blockAllocator * | pba, | |
void * | pblock | |||
) |
Frees a single block, returning it to the block pool.
[in,out] | pba | The allocator object the block came from. |
[in] | pblock | The block to return to the free block pool. |