ArrayAllocator< SIZE, ARRAYSELECTOR, FLUSH > Class Template Reference

#include <arrayallocator.h>

Detailed Description

template<Int SIZE, typename ARRAYSELECTOR, Bool FLUSH = false>
class maxon::ArrayAllocator< SIZE, ARRAYSELECTOR, FLUSH >

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.
ARRAYSELECTORSelector for array type to be used as allocator
FLUSHUse true if Flush() shall be called on the array instead of Reset() when all entries have been freed.

Classes

struct  FreeEntry
 

Public Types

using ValueType = ArrayAllocatorValueType< SIZE >
 
using ArrayType = typename ARRAYSELECTOR::template Type< ValueType >
 
using IsArrayAllocator = std::true_type
 

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
 
ArrayTypeGetArray ()
 
const ArrayTypeGetArray () const
 
template<typename T >
Bool DeleteAll ()
 

Private Attributes

Int _usedEntryCnt
 
FreeEntry_freeEntry
 
ArrayType _buffer
 

Member Typedef Documentation

◆ ValueType

◆ ArrayType

using ArrayType = typename ARRAYSELECTOR::template Type<ValueType>

◆ IsArrayAllocator

using IsArrayAllocator = std::true_type

Constructor & Destructor Documentation

◆ ArrayAllocator() [1/2]

Default Constructor.

◆ ArrayAllocator() [2/2]

ArrayAllocator ( ArrayAllocator< SIZE, ARRAYSELECTOR, FLUSH > &&  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]

ArrayType& GetArray ( )

◆ GetArray() [2/2]

const ArrayType& GetArray ( ) const

◆ DeleteAll()

Bool DeleteAll ( )

Member Data Documentation

◆ _usedEntryCnt

Int _usedEntryCnt
private

◆ _freeEntry

FreeEntry* _freeEntry
private

◆ _buffer

ArrayType _buffer
private