Class Allocator
Defined in File blockAllocator.h
Page Contents
Nested Relationships
Nested Types
Inheritance Relationships
Derived Type
public AllocatorPool< T, Objects >
(Template Class AllocatorPool)
Class Documentation
-
class Allocator
Inheritence diagram for Allocator:
See http://www.codeproject.com/Articles/1083210/An-efficient-Cplusplus-fixed-block-memory-allocato
Subclassed by AllocatorPool< T, Objects >
Public Functions
-
Allocator(size_t size, usint objects = 0, char *memory = nullptr, const char *name = nullptr)
Constructor
- Parameters
size – [in] - size of the fixed blocks
objects – [in] - maximum number of object. If 0, new blocks are created off the heap as necessary.
memory – [in] - pointer to a block of static memory for allocator or nullptr to obtain memory from global heap. If not nullptr, the objects argument defines the size of the memory block (size x objects = memory size in bytes).
name – [in] - optional allocator name string.
-
~Allocator()
Destructor.
-
void *Allocate(size_t size)
Get a pointer to a memory block.
- Parameters
size – [in] - size of the block to allocate
- Returns
Returns pointer to the block. Otherwise nullptr if unsuccessful.
-
void Deallocate(void *pBlock)
Return a pointer to the memory pool.
- Parameters
pBlock – [in] - block of memory deallocate (i.e push onto free-list)
-
inline const char *GetName()
Get the allocator name string.
- Returns
A pointer to the allocator name or nullptr if none was assigned.
-
inline size_t GetBlockSize()
Gets the fixed block memory size, in bytes, handled by the allocator.
- Returns
The fixed block size in bytes.
-
inline usint GetBlockCount()
Gets the maximum number of blocks created by the allocator.
- Returns
The number of fixed memory blocks created.
-
inline usint GetBlocksInUse()
Gets the number of blocks in use.
- Returns
The number of blocks in use by the application.
-
Allocator(size_t size, usint objects = 0, char *memory = nullptr, const char *name = nullptr)