Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Burger::MemoryManager Struct Reference

Base class for memory managers. More...

Inheritance diagram for Burger::MemoryManager:
Inheritance graph
[legend]
Collaboration diagram for Burger::MemoryManager:
Collaboration graph
[legend]

Public Types

typedef void *(* ProcAlloc) (MemoryManager *pThis, uintptr_t uSize)
 Function prototype for allocating memory.
 
typedef void(* ProcFree) (MemoryManager *pThis, const void *pInput)
 Function prototype for releasing memory.
 
typedef void *(* ProcRealloc) (MemoryManager *pThis, const void *pInput, uintptr_t uSize)
 Function prototype for reallocating memory.
 
typedef void(* ProcShutdown) (MemoryManager *pThis)
 Function prototype for destructor.
 

Public Member Functions

voidalloc (uintptr_t uSize) noexcept
 Allocate memory.
 
void free (const void *pInput) noexcept
 Release memory.
 
voidrealloc (const void *pInput, uintptr_t uSize) noexcept
 Reallocate memory.
 
void shutdown (void) noexcept
 Shut down the memory manager.
 
voidalloc_clear (uintptr_t uSize) noexcept
 Allocate a block of pre-zeroed memory.
 

Static Public Member Functions

static void shutdown (MemoryManager *pThis) noexcept
 Default memory manager destructor.
 

Public Attributes

ProcAlloc m_pAlloc
 Pointer to allocation function.
 
ProcFree m_pFree
 Pointer to memory release function.
 
ProcRealloc m_pRealloc
 Pointer to the memory reallocation function.
 
ProcShutdown m_pShutdown
 Pointer to the shutdown function.
 

Detailed Description

Base class for memory managers.


To avoid the use of virtual pointers and to gain ANSI C compatibility, the "base class" has all the virtual functions defined explicitly, and calls to the base class are passed through the function pointers while calls to the derived classed (When known) are performed by direct calls.

Since this is defined as a base class, it's not meant to be used directly. You should derive from this class and either implement your own memory handler, or use the predefined MemoryManagerANSI or MemoryManagerHandle classes.

Member Typedef Documentation

◆ ProcAlloc

typedef void *( * Burger::MemoryManager::ProcAlloc) (MemoryManager *pThis, uintptr_t uSize)

Function prototype for allocating memory.

◆ ProcFree

typedef void( * Burger::MemoryManager::ProcFree) (MemoryManager *pThis, const void *pInput)

Function prototype for releasing memory.

◆ ProcRealloc

typedef void *( * Burger::MemoryManager::ProcRealloc) (MemoryManager *pThis, const void *pInput, uintptr_t uSize)

Function prototype for reallocating memory.

◆ ProcShutdown

typedef void( * Burger::MemoryManager::ProcShutdown) (MemoryManager *pThis)

Function prototype for destructor.

Member Function Documentation

◆ alloc()

Burger::MemoryManager::alloc ( uintptr_t uSize)
inlinenoexcept

Allocate memory.


Call the "virtual" function in m_pAlloc to allocate memory

Parameters
uSizeNumber of bytes to allocate
Returns
Pointer to valid memory or nullptr on error or no memory requested.
See also
free() or alloc_clear()

◆ alloc_clear()

void *BURGER_API Burger::MemoryManager::alloc_clear ( uintptr_t uSize)
noexcept

Allocate a block of pre-zeroed memory.


Allocate a block of memory and return either nullptr in the case of an out of memory condition or if the amount requested was zero, otherwise return a valid pointer of memory that has been preset to zero.

Parameters
uSizeNumber of bytes to allocate.
Returns
nullptr on error or a valid pointer to allocated memory.
See also
alloc() or realloc()

◆ free()

Burger::MemoryManager::free ( const void * pInput)
inlinenoexcept

Release memory.


Call the "virtual" function in m_pFree to allocate memory

Parameters
pInputPointer to memory to release
See also
alloc() or alloc_clear()

◆ realloc()

Burger::MemoryManager::realloc ( const void * pInput,
uintptr_t uSize )
inlinenoexcept

Reallocate memory.


Call the "virtual" function in m_pRealloc to reallocate memory

Parameters
pInputPointer to memory to read from and release
uSizeNumber of bytes to allocate
Returns
Pointer to valid memory or nullptr on error or no memory requested.
See also
alloc() or free()

◆ shutdown() [1/2]

void BURGER_API Burger::MemoryManager::shutdown ( MemoryManager * pThis)
staticnoexcept

Default memory manager destructor.


This function does nothing. It's intended to be a placeholder for derived memory managers that do not have shutdown functions (Such as those that have the OS or ANSI malloc/free to perform these operations)

Parameters
pThisThe "this" pointer

◆ shutdown() [2/2]

void Burger::MemoryManager::shutdown ( void )
inlinenoexcept

Shut down the memory manager.


Call the "virtual" function in m_pShutdown to shut down the memory system

Member Data Documentation

◆ m_pAlloc

ProcAlloc Burger::MemoryManager::m_pAlloc

Pointer to allocation function.

◆ m_pFree

ProcFree Burger::MemoryManager::m_pFree

Pointer to memory release function.

◆ m_pRealloc

ProcRealloc Burger::MemoryManager::m_pRealloc

Pointer to the memory reallocation function.

◆ m_pShutdown

ProcShutdown Burger::MemoryManager::m_pShutdown

Pointer to the shutdown function.