ML Reference
MLMemoryManager Class Reference

The memory manager. More...

#include <mlMemoryManager.h>

Public Member Functions

 ~MLMemoryManager ()
unsigned int registerLibrary (const std::string &libraryName)
void setErrorHandlingCallback (MLMemoryManagerErrorHandler errorHandler)
void clearMemoryBlockHandles (MLMemoryBlockHandle **handles, size_t handleCount)
void clearMemoryBlockHandles (MLWeakMemoryBlockHandle **handles, size_t handleCount)
MLMemoryBlockHandle allocate (unsigned int id, size_t size)
MLMemoryBlockHandle addAllocatedMemory (unsigned int id, void *data, size_t size, MLDeleteMemoryBlockCallback deleteMemoryBlockCallback, void *deleteMemoryBlockCallbackUserData)
void setCacheAndLockedMemorySizeLimit (const size_t cacheSizeLimit)
size_t clearCachedMemory (size_t numBytes)
void clearCache ()
void clearCacheToLimit ()
size_t cacheAndLockedMemorySizeLimit () const
size_t cacheSize () const
size_t lockedMemorySize () const
size_t cacheAndLockedMemorySize () const
void printCache (std::ostream &out) const
void setStatisticsEnabled (bool enabled)
void printStatistics (std::ostream &out)

Static Public Member Functions

static void initialize ()
static void deinitialize ()
static MLMemoryManagersingleton ()
enum class  Ownership { UserDataOwnershipStaysWithCaller , UserDataOwnershipGoesToMemoryBlock }
template<typename T>
static bool registerDeletionCallbackUnsafe (const T &handle, MLDeleteMemoryBlockCallback callback, void *userData)
template<typename T>
static Ownership deregisterDeletionCallbackUnsafe (const T &handle, MLDeleteMemoryBlockCallback callback, const void *userData)
boost::mutex & getCacheAccessMutex ()
template<typename T>
void replaceDeletionCallback (const T &handle, MLDeleteMemoryBlockCallback newCallback, void *newUserData, MLDeleteMemoryBlockCallback *oldCallback=nullptr, void **oldUserData=nullptr) const

Detailed Description

The memory manager.

Definition at line 86 of file mlMemoryManager.h.

Member Enumeration Documentation

◆ Ownership

enum class MLMemoryManager::Ownership
strong
Enumerator
UserDataOwnershipStaysWithCaller 
UserDataOwnershipGoesToMemoryBlock 

Definition at line 212 of file mlMemoryManager.h.

Constructor & Destructor Documentation

◆ ~MLMemoryManager()

MLMemoryManager::~MLMemoryManager ( )

Member Function Documentation

◆ clearMemoryBlockHandles() [1/2]

void MLMemoryManager::clearMemoryBlockHandles ( MLMemoryBlockHandle ** handles,
size_t handleCount )

Clears a list of memory block handles. The cache access mutex will be locked only once. NULL pointers are allowed in handles; they will be ignored.

◆ clearMemoryBlockHandles() [2/2]

void MLMemoryManager::clearMemoryBlockHandles ( MLWeakMemoryBlockHandle ** handles,
size_t handleCount )

Clears a list of weak memory block handles. The cache access mutex will be locked only once. NULL pointers are allowed in handles; they will be ignored.

◆ deinitialize()

void MLMemoryManager::deinitialize ( )
static

Deinitializes the memory manager. This function should be called at program termination, when no library accesses the memory manager anymore. This also means that no strong or weak handle may exist at this time; otherwise, they would be destroyed after the memory manager and try to communicate with it, causing a crash. Calling deinitialize() multiple times is allowed.

◆ deregisterDeletionCallbackUnsafe()

template<typename T>
template MLMemoryManager::Ownership MLMEMORYMANAGER_EXPORT MLMemoryManager::deregisterDeletionCallbackUnsafe< MLMemoryBlockHandle > ( const T & handle,
MLDeleteMemoryBlockCallback callback,
const void * userData )
static

◆ getCacheAccessMutex()

boost::mutex & MLMemoryManager::getCacheAccessMutex ( )

Advanced memory manager handling. Returns the cache access mutex. Make sure you know what you are doing when using this mutex!

◆ initialize()

void MLMemoryManager::initialize ( )
static

Initializes the memory manager with a default limit of one gigabyte for the joint size of the cache and the locked memory. Calling this function more than once is allowed and has no effect. Deinitialization can be done by calling deinitialize(), which is also automatically called when the memory manager library is unloaded. The default cache and locked memory size limit can be adjusted with setCacheAndLockedMemorySizeLimit.

◆ registerDeletionCallbackUnsafe()

template<typename T>
template bool MLMEMORYMANAGER_EXPORT MLMemoryManager::registerDeletionCallbackUnsafe< MLMemoryBlockHandle > ( const T & handle,
MLDeleteMemoryBlockCallback callback,
void * userData )
static

◆ registerLibrary()

unsigned int MLMemoryManager::registerLibrary ( const std::string & libraryName)

Registers a library and returns an ID. This ID must be passed to allocate() and addAllocatedMemory(), and is used for generating statistics about cache and locked memory usage of different libraries.

◆ replaceDeletionCallback()

template<typename T>
template void MLMEMORYMANAGER_EXPORT MLMemoryManager::replaceDeletionCallback< MLMemoryBlockHandle > ( const T & handle,
MLDeleteMemoryBlockCallback newCallback,
void * newUserData,
MLDeleteMemoryBlockCallback * oldCallback = nullptr,
void ** oldUserData = nullptr ) const

Replaces the deletion callback and user data that are registered for the memory block. IMPORTANT: The cache access mutex must be locked before calling this function! handles that reference the same memory block.

Deprecated
use registerDeletionCallbackUnsafe/deregisterDeletionCallbackUnsafe instead

◆ setErrorHandlingCallback()

void MLMemoryManager::setErrorHandlingCallback ( MLMemoryManagerErrorHandler errorHandler)

Sets the error handler callback.

See also
MLMemoryManagerErrorHandler

◆ singleton()

MLMemoryManager * MLMemoryManager::singleton ( )
static

The singleton is the only way to communicate with the memory manager. The pointer may never be deleted, this is handled in the deinitialization.


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