Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
FixedSizeAllocator Struct Reference

Detailed Description

This is a fixed size allocator implementation for the abstract interface class AllocatorIntf.

The FixedSizeAllocator takes a buffer and splits the buffer up into equally sized chunks. Allocating memory larger than the chunk size or using realloc results in an error; i.e., NULL returned. One can allocate a smaller size than the chunk size, but the size will be adjusted to the chunk size. A zero-size request or exhausted pool returns NULL and sets the requested size to zero. Free only live blocks returned by this allocator, once each; NULL is not accepted. The backing buffer remains owned by the caller and must outlive the allocator and all allocated blocks. This allocator does not lock access; callers must serialize concurrent use.

#include <FixedSizeAllocator.h>

Inheritance diagram for FixedSizeAllocator:

Public Member Functions

 FixedSizeAllocator ()
 Leave storage uninitialized; call FixedSizeAllocator_constructor before use. More...
 
 FixedSizeAllocator (void *buffer, size_t bufSize, size_t blockSize)
 Initialize a fixed-size allocation pool without allocating memory. More...
 
- Public Member Functions inherited from AllocatorIntf
 AllocatorIntf ()
 Leave callbacks uninitialized; initialize them before use. More...
 
 AllocatorIntf (AllocatorIntf_Malloc malloc, AllocatorIntf_Realloc realloc, AllocatorIntf_Free free)
 Create an instance of a memory allocation class. More...
 
void * malloc (size_t *size)
 Allocate uninitialized storage. More...
 
void * malloc (size_t size)
 Allocate without returning the adjusted allocation size. More...
 
void * realloc (void *p, size_t *size)
 Resize an allocation. More...
 
void * realloc (void *p, size_t size)
 Resize without returning the adjusted allocation size. More...
 
void free (void *p)
 Release an allocation. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from AllocatorIntf
static AllocatorIntf * getDefault (void)
 Obtain the shared allocator backed by baMalloc, baRealloc and baFree. More...
 

Constructor & Destructor Documentation

◆ FixedSizeAllocator() [1/2]

FixedSizeAllocator::FixedSizeAllocator ( )

Leave storage uninitialized; call FixedSizeAllocator_constructor before use.

◆ FixedSizeAllocator() [2/2]

FixedSizeAllocator::FixedSizeAllocator ( void *  buffer,
size_t  bufSize,
size_t  blockSize 
)

Initialize a fixed-size allocation pool without allocating memory.

Parameters
[in,out]bufferWritable backing storage, aligned for SingleLink and for the objects to be allocated from it. Initialization writes free list links into the buffer.
[in]bufSizeAvailable bytes. Only complete blocks are used; trailing bytes smaller than blockSize are unused.
[in]blockSizePositive bytes per block, at least sizeof(SingleLink) and a multiple of the required alignment. The buffer-size arithmetic must fit in size_t. No argument-validation status is returned.