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

The allocator interface. More...

#include <IAllocator.h>

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

Public Types

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

 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)
 

Static Public Attributes

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

AllocateFunction allocateFunc_
 
ReallocateFunction reallocateFunc_
 
DeallocateFunction deallocateFunc_
 
char name_ [MaxNameLength]
 
size_t size_
 
voidbase_
 
size_t usedMemory_
 
size_t numAllocations_
 
bool copyOnReallocation_
 

Friends

class ProxyAllocator
 

Detailed Description

The allocator interface.

Member Function Documentation

◆ freeMemory()

size_t nctl::IAllocator::freeMemory ( ) const
inline

Returns the amount of memory available in the buffer It can be less than the memory availble to allocations due to overhead or fragmentation *‍/

◆ setCopyOnReallocation()

void nctl::IAllocator::setCopyOnReallocation ( bool  value)
inline

Sets the state of the copy on reallocation flag.

Note
When the flag is true a growing reallocation might move the data in a new place

◆ usedMemory()

size_t nctl::IAllocator::usedMemory ( ) const
inline

Returns the amount of memory in use

Note
It can be more than the memory used by allocations due to overhead *‍/

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