CustomAllocatorInterface Class Reference

#include <customallocator.h>

Detailed Description

Custom allocator/memory pool interface.

Public Member Functions

 MAXON_ADD_TO_REFERENCE_CLASS (Int ComputeArraySize(Int currentSize, Int increment, Int minChunkSize) { return DefaultAllocator::ComputeArraySize(currentSize, increment, minChunkSize);})
 
MAXON_METHOD void * Alloc (Int s, MAXON_SOURCE_LOCATION_DECLARATION)
 
MAXON_METHOD void * AllocClear (Int s, MAXON_SOURCE_LOCATION_DECLARATION)
 
MAXON_METHOD void * Realloc (void *data, Int size, MAXON_SOURCE_LOCATION_DECLARATION)
 
 MAXON_ADD_TO_REFERENCE_CLASS (template< typename T > void Free(T *&p) { if(this->GetPointer()) this->GetPointer() ->PrivateFree(static_cast< void * >(p));p=nullptr;})
 
 MAXON_ADD_TO_REFERENCE_CLASS (Bool IsCompatibleWithDefaultAllocator(void *) const { return false;})
 
MAXON_METHOD void * PrivateAlloc (Int size, Bool clear, MAXON_SOURCE_LOCATION_DECLARATION)
 
MAXON_METHOD void PrivateFree (void *data)
 
MAXON_METHOD Int PrivateGetDataSize (void *data)
 

Static Public Member Functions

static MAXON_METHOD CustomAllocatorInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (CustomAllocatorInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.customallocator")
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( CustomAllocatorInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.customallocator"   
)
private

◆ Alloc() [1/2]

Parameters
[in]allocLocationSource location.

◆ MAXON_ADD_TO_REFERENCE_CLASS() [1/3]

MAXON_ADD_TO_REFERENCE_CLASS ( Int ComputeArraySize(Int currentSize, Int increment, Int minChunkSize) { return DefaultAllocator::ComputeArraySize(currentSize, increment, minChunkSize);}  )

Computes the new capacity 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 capacity (maximum number of elements).

◆ Alloc() [2/2]

Allocates a memory block. THREADSAFE. 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.

◆ AllocClear()

MAXON_METHOD void* AllocClear ( Int  s,
MAXON_SOURCE_LOCATION_DECLARATION   
)

Allocates a memory block and clears it. THREADSAFE.

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()

MAXON_METHOD void* Realloc ( void *  data,
Int  size,
MAXON_SOURCE_LOCATION_DECLARATION   
)

Resizes an allocated memory block. If allocation of a new block fails the old one won't be freed.

Parameters
[in]dataData location, can be nullptr.
[in]sizeMinimum new data size (values < 0 will return nullptr).
[in]allocLocationStructure with caller data like source file and source line.
Returns
Data pointer or nullptr.

◆ MAXON_ADD_TO_REFERENCE_CLASS() [2/3]

MAXON_ADD_TO_REFERENCE_CLASS ( template< typename T > void Free(T *&p) { if(this->GetPointer()) this->GetPointer() ->PrivateFree(static_cast< void * >(p));p=nullptr;}  )

◆ MAXON_ADD_TO_REFERENCE_CLASS() [3/3]

MAXON_ADD_TO_REFERENCE_CLASS ( Bool IsCompatibleWithDefaultAllocator(void *) const { return false;}  )

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

Returns
True if the memory block can be reallocated or freed by the DefaultAllocator.

◆ PrivateAlloc()

MAXON_METHOD void* PrivateAlloc ( Int  size,
Bool  clear,
MAXON_SOURCE_LOCATION_DECLARATION   
)

Allocates a block of memory.

Parameters
[in]sizeMinimum data size (values < 0 will return nullptr).
[in]clearIf the data should be cleared this must be true.
[in]allocLocationStructure with caller data like source file and source line.
Returns
Data pointer or nullptr.

◆ PrivateFree()

MAXON_METHOD void PrivateFree ( void *  data)

Frees a memory block (might have been allocated by a different local Allocator of the same type).

Parameters
[in]dataPointer as returned by Alloc, guaranteed to be valid and not nullptr.

◆ PrivateGetDataSize()

MAXON_METHOD Int PrivateGetDataSize ( void *  data)

Returns the maximum size of an allocated block (might be bigger than what was acutally allocated).

Parameters
[in]dataPointer as returned by Alloc, guaranteed to be valid and != nullptr.
Returns
Block size in bytes (>=allocated size) or 0.