CStdLibAllocator Class Reference

#include <cstdliballocator.h>

Detailed Description

C stdlib memory allocator. This allocator forwards all requests to malloc(), realloc() and free(). It is much slower than the DefaultAllocator and should only be used, if your code requires memory directly from the C stdlib.

THREADSAFE.

Static Public Member Functions

static Int ComputeArraySize (Int currentSize, Int increment, Int minChunkSize)
 
static void * Alloc (Int32 s, MAXON_SOURCE_LOCATION_DECLARATION)
 
static void * Alloc (Int64 s, MAXON_SOURCE_LOCATION_DECLARATION)
 
static void * AllocClear (Int32 s, MAXON_SOURCE_LOCATION_DECLARATION)
 
static void * AllocClear (Int64 s, MAXON_SOURCE_LOCATION_DECLARATION)
 
static void * Realloc (void *p, Int32 n, MAXON_SOURCE_LOCATION_DECLARATION)
 
static void * Realloc (void *p, Int64 n, MAXON_SOURCE_LOCATION_DECLARATION)
 
template<typename T >
static void Free (T *&p)
 
static Bool IsCompatibleWithDefaultAllocator (void *)
 

Member Function Documentation

◆ ComputeArraySize()

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

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() [1/2]

static void* Alloc ( Int32  s,
MAXON_SOURCE_LOCATION_DECLARATION   
)
static

Allocates a memory block. The memory is not cleared, it may contain a certain byte pattern in debug mode 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.

◆ Alloc() [2/2]

static void* Alloc ( Int64  s,
MAXON_SOURCE_LOCATION_DECLARATION   
)
static

Allocates a memory block. The memory is not cleared, it may contain a certain byte pattern in debug mode 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.

◆ AllocClear() [1/2]

static void* AllocClear ( Int32  s,
MAXON_SOURCE_LOCATION_DECLARATION   
)
static

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.

◆ AllocClear() [2/2]

static void* AllocClear ( Int64  s,
MAXON_SOURCE_LOCATION_DECLARATION   
)
static

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() [1/2]

static void* Realloc ( void *  p,
Int32  n,
MAXON_SOURCE_LOCATION_DECLARATION   
)
static

Resizes a memory block. The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. The additional memory is not cleared, it may contain a certain byte pattern in debug mode. In case that p is a nullptr the function behaves like Alloc. If the function fails to allocate the requested block of memory a nullptr is returned and the memory block pointed to by argument p is not deallocated (it is still valid with its contents unchanged). THREADSAFE.

Parameters
[in]pCurrent memory block (can be nullptr)
[in]nNew block 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 if resize is not possible (p is still valid in this case)

◆ Realloc() [2/2]

static void* Realloc ( void *  p,
Int64  n,
MAXON_SOURCE_LOCATION_DECLARATION   
)
static

Resizes a memory block. The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. The additional memory is not cleared, it may contain a certain byte pattern in debug mode. In case that p is a nullptr the function behaves like Alloc. If the function fails to allocate the requested block of memory a nullptr is returned and the memory block pointed to by argument p is not deallocated (it is still valid with its contents unchanged). THREADSAFE.

Parameters
[in]pCurrent memory block (can be nullptr)
[in]nNew block 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 if resize is not possible (p is still valid in this case)

◆ Free()

static void Free ( T *&  p)
static

Frees a memory block. THREADSAFE.

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

◆ IsCompatibleWithDefaultAllocator()

static Bool IsCompatibleWithDefaultAllocator ( void *  )
static

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

Returns
Always false.