ArrayAllocator< SIZE, ARRAY > Class Template Reference

#include <arrayallocator.h>

Detailed Description

template<Int SIZE, typename ARRAY>
class maxon::ArrayAllocator< SIZE, ARRAY >

Array allocator which only allocates and frees entries of SIZE bytes. Depending on the type of array the allocation might relocate already existing items.

Template Parameters
SIZEThe size of an entry in bytes.
ARRAYArray to be used as allocator

Classes

struct  FreeEntry
 

Public Member Functions

 ArrayAllocator ()
 
 ArrayAllocator (ArrayAllocator &&src)
 
Int ComputeArraySize (Int currentSize, Int increment, Int minChunkSize)
 
void * Alloc (Int64 s, MAXON_SOURCE_LOCATION_DECLARATION)
 
void * Realloc (void *, Int64, MAXON_SOURCE_LOCATION_DECLARATION)
 
template<typename T >
void Free (T *&p)
 
Bool IsCompatibleWithDefaultAllocator (void *p) const
 
ARRAY & GetArray ()
 
const ARRAY & GetArray () const
 

Private Attributes

Int _usedEntryCnt
 
FreeEntry_freeEntry
 
ARRAY _buffer
 

Constructor & Destructor Documentation

◆ ArrayAllocator() [1/2]

Default Constructor.

◆ ArrayAllocator() [2/2]

ArrayAllocator ( ArrayAllocator< SIZE, ARRAY > &&  src)

Move constructor.

Member Function Documentation

◆ ComputeArraySize()

Int ComputeArraySize ( Int  currentSize,
Int  increment,
Int  minChunkSize 
)

Computes the new size for a growing array THREADSAFE.

Parameters
[in]currentSizeCurrent number of elements.
[in]incrementNumber of elements to be added (>= 1)
[in]minChunkSizeThe minimum number of elements upon array creation.
Returns
New number of elements.

◆ Alloc()

void* Alloc ( Int64  s,
MAXON_SOURCE_LOCATION_DECLARATION   
)

Allocates a memory block. The memory is not cleared, it may contain a certain byte pattern in debug mode.

Parameters
[in]sBlock size in bytes (values < 0 will return nullptr)
[in]allocLocationPass MAXON_SOURCE_LOCATION(_NAME) to add the current source line and file.
Returns
Memory block address or nullptr.

◆ Realloc()

void* Realloc ( void *  ,
Int64  ,
MAXON_SOURCE_LOCATION_DECLARATION   
)

Not supported for this allocator.

Returns
nullptr

◆ Free()

void Free ( T *&  p)

Frees a memory block.

Parameters
[in,out]pMemory block address (can be nullptr, will be nullptr after return)

◆ IsCompatibleWithDefaultAllocator()

Bool IsCompatibleWithDefaultAllocator ( void *  p) const

Returns if a memory block allocated via this allocator can be reallocated or freed by the DefaultAllocator.

Parameters
[in]pMemory block address.
Returns
True if the memory block can be reallocated or freed by the DefaultAllocator.

◆ GetArray() [1/2]

ARRAY& GetArray ( )

◆ GetArray() [2/2]

const ARRAY& GetArray ( ) const

Member Data Documentation

◆ _usedEntryCnt

Int _usedEntryCnt
private

◆ _freeEntry

FreeEntry* _freeEntry
private

◆ _buffer

ARRAY _buffer
private