|
Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
|
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>

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... | |
| FixedSizeAllocator::FixedSizeAllocator | ( | ) |
Leave storage uninitialized; call FixedSizeAllocator_constructor before use.
| FixedSizeAllocator::FixedSizeAllocator | ( | void * | buffer, |
| size_t | bufSize, | ||
| size_t | blockSize | ||
| ) |
Initialize a fixed-size allocation pool without allocating memory.
| [in,out] | buffer | Writable backing storage, aligned for SingleLink and for the objects to be allocated from it. Initialization writes free list links into the buffer. |
| [in] | bufSize | Available bytes. Only complete blocks are used; trailing bytes smaller than blockSize are unused. |
| [in] | blockSize | Positive 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. |