Class Allocator

Nested Relationships

Nested Types

Inheritance Relationships

Derived Type

Class Documentation

class Allocator

Inheritence diagram for Allocator:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="AllocatorPool< T, Objects >" tooltip="AllocatorPool< T, Objects >"] "1" [label="Allocator" tooltip="Allocator" fillcolor="#BFBFBF"] "2" -> "1" [dir=forward tooltip="public-inheritance"] }

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.

inline usint GetAllocations()

Gets the total number of allocations for this allocator instance.

Returns

The total number of allocations.

inline usint GetDeallocations()

Gets the total number of deallocations for this allocator instance.

Returns

The total number of deallocations.