Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
No Matches
Static Public Member Functions | Static Private Attributes | List of all members
Burger::GlobalMemoryManager Class Reference

Singleton class for global memory allocation. More...

Collaboration diagram for Burger::GlobalMemoryManager:
Collaboration graph

Static Public Member Functions

static MemoryManagerinit (MemoryManager *pInstance) noexcept
 Initialize the global memory allocator.
static void shutdown (MemoryManager *pPrevious=nullptr) noexcept
 Shut down the global memory allocator.
static MemoryManagerget_instance (void) noexcept
 Return the instance of the active global memory manager.

Static Private Attributes

static MemoryManagerg_pInstance
 Pointer to the currently active memory manager.

Detailed Description

Singleton class for global memory allocation.

To implement a workable copy of malloc(), free() etc., a method was needed to contain the instance pointer of the Burgerlib memory manager and retain the ability to change the implementation at will. This was needed since Burgerlib Memory Managers are all class based so a "this" pointer is needed in all calls whereas the ANSI calling convention assumes a global implementation.

By using this class, which is initialized either with Burger::MemoryManagerANSI or Burger::MemoryManagerHandle all functions that allocate memory from the global pool can and will be redirected.

Mostly used to make search and replace of malloc and new trivial. Use of this class is not encouraged. It's only for quick porting of legacy code that isn't multi-thread friendly.

This class is assumed to have functions that are thread safe. Any custom implementations on target platforms that support multi-threading must all be multi-core thread safe.
Since this a reference to the controlled class, NEVER manually up cast the global instance of this class. Use the get_instance(void) function to get the pointer to the real class if up casting is desired for system specific functionality is desired.

Member Function Documentation

◆ get_instance()

Burger::GlobalMemoryManager::get_instance ( void )

Return the instance of the active global memory manager.

Pointer to the current global memory manager, nullptr if none is active.

◆ init()

Burger::MemoryManager *BURGER_API Burger::GlobalMemoryManager::init ( MemoryManager * pInstance)

Initialize the global memory allocator.

This function copies the pointer to the MemoryManager class and will use this instance for all memory operations.

The MemoryManager is not copied, so the class should not go out of scope without a call to either shutdown() or reset to another implementation
pInstancePointer to an initialized MemoryManager.
Pointer to the previous version of the MemoryManager
See also
shutdown(MemoryManager *)

◆ shutdown()

void BURGER_API Burger::GlobalMemoryManager::shutdown ( MemoryManager * pPrevious = nullptr)

Shut down the global memory allocator.

Shut down the memory allocator through the Burger::MemoryManager::m_pShutdown pointer.

This call will zero out all entries in this class, so all future use of this class except for a call to init(MemoryManager *) will result in an assert or page fault.
pPreviousPointer to an previous MemoryManager.
See also
init(MemoryManager *)

Member Data Documentation

◆ g_pInstance

Burger::MemoryManager * Burger::GlobalMemoryManager::g_pInstance

Pointer to the currently active memory manager.