![]() |
nCine 2022.04.r504-20bd01e
A cross-platform 2D game engine
|
A free list allocator. More...
#include <FreeListAllocator.h>
Classes | |
struct | Block |
Public Types | |
enum class | FitStrategy { FIRST_FIT , BEST_FIT , WORST_FIT } |
Block allocation strategy. | |
![]() | |
using | AllocateFunction = void *(*)(IAllocator *allocator, size_t, uint8_t) |
using | ReallocateFunction = void *(*)(IAllocator *allocator, void *, size_t, uint8_t, size_t &) |
using | DeallocateFunction = void(*)(IAllocator *allocator, void *) |
Public Member Functions | |
FreeListAllocator (const char *name) | |
FreeListAllocator (size_t size, void *base) | |
FreeListAllocator (const char *name, size_t size, void *base) | |
FreeListAllocator (size_t size, void *base, bool defragOnDeallocation) | |
FreeListAllocator (const char *name, size_t size, void *base, bool defragOnDeallocation) | |
void | init (size_t size, void *base) |
void | defrag () |
Defragments free list blocks. | |
const Block * | freeBlock () const |
FitStrategy | fitStrategy () const |
Returns the allocation strategy. | |
void | setFitStrategy (FitStrategy fitStrategy) |
Sets the allocation strategy. | |
bool | defragOnDeallocation () const |
Returns the state of the defrag on deallocation flag. | |
void | setDefragOnDeallocation (bool value) |
Sets the state of the defrag on deallocation flag. | |
![]() | |
IAllocator (const char *name, AllocateFunction allocFunc, ReallocateFunction reallocFunc, DeallocateFunction deallocFunc) | |
IAllocator (const char *name, AllocateFunction allocFunc, ReallocateFunction reallocFunc, DeallocateFunction deallocFunc, size_t size, void *base) | |
void * | allocate (size_t bytes, uint8_t alignment) |
Tries to allocate the specified amount of memory with the specified alignment requirement. | |
void * | allocate (size_t bytes) |
void * | reallocate (void *ptr, size_t bytes, uint8_t alignment) |
Tries to reallocate the allocation at the specified pointer with a different size. | |
void * | reallocate (void *ptr, size_t bytes) |
void | deallocate (void *ptr) |
Deallocates the allocation at the specified pointer. | |
const char * | name () const |
Returns the name of the allocator. | |
size_t | size () const |
Returns the size of the buffer used for allocations. | |
void * | base () const |
Returns the address of the buffer used for allocations. | |
size_t | usedMemory () const |
size_t | freeMemory () const |
size_t | numAllocations () const |
Returns the number of active allocations. | |
bool | copyOnReallocation () const |
Returns the state of the copy on reallocation flag. | |
void | setCopyOnReallocation (bool value) |
Sets the state of the copy on reallocation flag. | |
template<class T , typename... Args> | |
T * | newObject (Args &&... args) |
template<class T > | |
void | deleteObject (T *ptr) |
template<class T > | |
T * | newArray (size_t numElements) |
template<class T > | |
void | deleteArray (T *ptr) |
Additional Inherited Members | |
![]() | |
static const uint8_t | DefaultAlignment = 2 * sizeof(void *) |
16 bytes default alignment on 64bit and 8 bytes on 32bit | |
static const unsigned int | MaxNameLength = 64 |
Maximum length for the allocator name string. | |
![]() | |
AllocateFunction | allocateFunc_ |
ReallocateFunction | reallocateFunc_ |
DeallocateFunction | deallocateFunc_ |
char | name_ [MaxNameLength] |
size_t | size_ |
void * | base_ |
size_t | usedMemory_ |
size_t | numAllocations_ |
bool | copyOnReallocation_ |
A free list allocator.
void nctl::FreeListAllocator::defrag | ( | ) |
Defragments free list blocks.
Sets the state of the defrag on deallocation flag.