#include <defaultallocator.h>
Static Public Member Functions | |
static Int | ComputeArraySize (Int current_size, Int increment, Int min_chunk_size) |
static void * | Alloc (Int32 s) |
static void * | Alloc (Int64 s) |
static void * | AllocClear (Int32 s) |
static void * | AllocClear (Int64 s) |
static void * | Realloc (void *p, Int n) |
template<class T > | |
static void | Free (T *&p) |
Default implementation of an allocator. An allocator is used by arrays, lists and other data structurs to allocate and release memory. By default this implementation of an allocator is used.
There might be rare cases when you need a special memory alignment, a different resize strategy or have to use a special memory area (stack, shared memory, ...). This can be done by writing a custom allocator and specifying it as parameter upon array construction. A custom allocator must implement the ComputeArraySize(), Alloc(), AllocClear(), Realloc() and Free() methods, but it doesn't (and usually shouldn't) inherit from DefaultAllocator. The allocator methods don't have to be static if your allocator requires member variables, but the DefaultAllocator doesn't and therefore uses static methods for better performance.
Please note that an allocator is copied upon array construction - it would be a bad idea if your custom allocator object would consist of more than a few variables.
THREADSAFE
Computes the new size for a growing array.
[in] | current_size | Current number of elements. |
[in] | increment | Number of elements to be added (>= 1) |
[in] | min_chunk_size | The minimum number of elements upon array creation. THREADSAFE. |
|
static |
Allocates a memory block. The memory is not cleared, it may contain a certain byte pattern in debug mode.
[in] | s | Block size in bytes (values < 0 will return nullptr) THREADSAFE. |
|
static |
Allocates a memory block. The memory is not cleared, it may contain a certain byte pattern in debug mode.
[in] | s | Block size in bytes (values < 0 will return nullptr) THREADSAFE. |
|
static |
Allocates a memory block and clears it.
[in] | s | Block size in bytes (values < 0 will return nullptr) THREADSAFE. |
|
static |
Allocates a memory block and clears it.
[in] | s | Block size in bytes (values < 0 will return nullptr) THREADSAFE. |
|
static |
Resizes a memory block. The additional memory is not cleared, it may contain a certain byte pattern in debug mode.
[in] | p | Current memory block (can be nullptr) |
[in] | n | New block size in bytes (values < 0 will return nullptr) THREADSAFE. |
|
static |
Frees a memory block.
[in,out] | p | Memory block address (can be nullptr, will be nullptr after return) THREADSAFE |