nCine 2022.04.r504-20bd01e
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
nctl::FreeListAllocator Class Reference

A free list allocator. More...

#include <FreeListAllocator.h>

Inheritance diagram for nctl::FreeListAllocator:
Inheritance graph
[legend]
Collaboration diagram for nctl::FreeListAllocator:
Collaboration graph
[legend]

Classes

struct  Block
 

Public Types

enum class  FitStrategy { FIRST_FIT , BEST_FIT , WORST_FIT }
 Block allocation strategy.
 
- Public Types inherited from nctl::IAllocator
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 BlockfreeBlock () 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.
 
- Public Member Functions inherited from nctl::IAllocator
 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)
 
voidallocate (size_t bytes, uint8_t alignment)
 Tries to allocate the specified amount of memory with the specified alignment requirement.
 
voidallocate (size_t bytes)
 
voidreallocate (void *ptr, size_t bytes, uint8_t alignment)
 Tries to reallocate the allocation at the specified pointer with a different size.
 
voidreallocate (void *ptr, size_t bytes)
 
void deallocate (void *ptr)
 Deallocates the allocation at the specified pointer.
 
const charname () const
 Returns the name of the allocator.
 
size_t size () const
 Returns the size of the buffer used for allocations.
 
voidbase () 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 Public Attributes inherited from nctl::IAllocator
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.
 
- Protected Attributes inherited from nctl::IAllocator
AllocateFunction allocateFunc_
 
ReallocateFunction reallocateFunc_
 
DeallocateFunction deallocateFunc_
 
char name_ [MaxNameLength]
 
size_t size_
 
voidbase_
 
size_t usedMemory_
 
size_t numAllocations_
 
bool copyOnReallocation_
 

Detailed Description

A free list allocator.

Member Function Documentation

◆ defrag()

void nctl::FreeListAllocator::defrag ( )

Defragments free list blocks.

Note
It does not alter allocated pointers

◆ setDefragOnDeallocation()

void nctl::FreeListAllocator::setDefragOnDeallocation ( bool  value)
inline

Sets the state of the defrag on deallocation flag.

Note
When the flag is true a defrag will automatically start after every deallocation

The documentation for this class was generated from the following files: