defs/si_sys/blkalloc.h File Reference

Fixed size block allocator. More...

#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)


Detailed Description

Fixed size block allocator.

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.


Function Documentation

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.

Parameters:
[in,out] pba The allocator object to allocate from.
[out] ppblock The allocated block returned at *ppblock.
Note:
This function operates in constant time.

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.

Parameters:
[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.

Note:
: All allocated blocks must be freed before the destructor is called.

sc_status sc_blockAllocator_free ( sc_blockAllocator pba,
void *  pblock 
)

Frees a single block, returning it to the block pool.

Parameters:
[in,out] pba The allocator object the block came from.
[in] pblock The block to return to the free block pool.
Note:
This function operates in constant time.


doxygen