DART 6.13.2
Loading...
Searching...
No Matches
dart::common::MemoryManager Class Referencefinal

A composite memory allocator that contains various memory allocators that are optimized for different use cases. More...

#include <MemoryManager.hpp>

Public Types

enum class  Type { Base , Free , Pool }
 Type of the memory allocators. More...
 

Public Member Functions

 MemoryManager (MemoryAllocator &baseAllocator=MemoryAllocator::GetDefault())
 Constructor.
 
 ~MemoryManager ()
 Destructor.
 
MemoryAllocatorgetBaseAllocator ()
 Returns the base allocator.
 
FreeListAllocatorgetFreeListAllocator ()
 Returns the free list allocator.
 
PoolAllocatorgetPoolAllocator ()
 Returns the pool allocator.
 
void * allocate (Type type, size_t bytes)
 Allocates size bytes of uninitialized storage.
 
void * allocateUsingFree (size_t bytes)
 Allocates size bytes of uninitialized storage using FreeListAllocator.
 
void * allocateUsingPool (size_t bytes)
 Allocates size bytes of uninitialized storage using PoolAllocator.
 
void deallocate (Type type, void *pointer, size_t bytes)
 Deallocates the storage referenced by the pointer p, which must be a pointer obtained by an earlier cal to allocate().
 
void deallocateUsingFree (void *pointer, size_t bytes)
 
void deallocateUsingPool (void *pointer, size_t bytes)
 
template<typename T , typename... Args>
T * construct (Type type, Args &&... args) noexcept
 Allocates uninitialized storage and constructs an object of type T to the allocated storage.
 
template<typename T , typename... Args>
T * constructUsingFree (Args &&... args) noexcept
 Allocates uninitialized storage using FreeListAllocator and constructs an object of type T to the allocated storage.
 
template<typename T , typename... Args>
T * constructUsingPool (Args &&... args) noexcept
 Allocates uninitialized storage using PoolAllocator and constructs an object of type T to the allocated storage.
 
template<typename T >
void destroy (Type type, T *object) noexcept
 Calls the destructor of the object and deallocate the storage.
 
template<typename T >
void destroyUsingFree (T *pointer) noexcept
 Calls the destructor of the object and deallocate the storage using FreeListAllocator.
 
template<typename T >
void destroyUsingPool (T *pointer) noexcept
 Calls the destructor of the object and deallocate the storage using PoolAllocator.
 
bool hasAllocated (void *pointer, size_t size) const noexcept
 Returns true if a pointer is allocated by the internal allocator.
 
void print (std::ostream &os=std::cout, int indent=0) const
 Prints state of the memory manager.
 

Static Public Member Functions

static MemoryManagerGetDefault ()
 Returns the default memory manager.
 

Private Attributes

MemoryAllocatormBaseAllocator
 The base allocator to allocate memory chunck.
 
FreeListAllocator::Debug mFreeListAllocator
 The free list allocator.
 
PoolAllocator::Debug mPoolAllocator
 The pool allocator.
 

Friends

std::ostream & operator<< (std::ostream &os, const MemoryManager &memoryManager)
 Prints state of the memory manager.
 

Detailed Description

A composite memory allocator that contains various memory allocators that are optimized for different use cases.

Member Enumeration Documentation

◆ Type

Type of the memory allocators.

Enumerator
Base 
Free 
Pool 

Constructor & Destructor Documentation

◆ MemoryManager()

dart::common::MemoryManager::MemoryManager ( MemoryAllocator baseAllocator = MemoryAllocator::GetDefault())
explicit

Constructor.

Parameters
[in]baseAllocator(optional) The most low level allocator to be used by all the underlying memory allocators.

◆ ~MemoryManager()

dart::common::MemoryManager::~MemoryManager ( )

Destructor.

Member Function Documentation

◆ allocate()

void * dart::common::MemoryManager::allocate ( Type  type,
size_t  bytes 
)

Allocates size bytes of uninitialized storage.

Parameters
[in]typeThe memory allocator type.
[in]bytesThe byte size to allocate sotrage for.
Returns
On success, the pointer to the beginning of newly allocated memory.
On failure, a null pointer

◆ allocateUsingFree()

void * dart::common::MemoryManager::allocateUsingFree ( size_t  bytes)

Allocates size bytes of uninitialized storage using FreeListAllocator.

Parameters
[in]bytesThe byte size to allocate sotrage for.
Returns
On success, the pointer to the beginning of newly allocated memory.
On failure, a null pointer

◆ allocateUsingPool()

void * dart::common::MemoryManager::allocateUsingPool ( size_t  bytes)

Allocates size bytes of uninitialized storage using PoolAllocator.

Parameters
[in]bytesThe byte size to allocate sotrage for.
Returns
On success, the pointer to the beginning of newly allocated memory.
On failure, a null pointer

◆ construct()

template<typename T , typename... Args>
T * dart::common::MemoryManager::construct ( Type  type,
Args &&...  args 
)
noexcept

Allocates uninitialized storage and constructs an object of type T to the allocated storage.

Template Parameters
TThe object type to construct.
Args...The argument types to pass to the object constructor.
Parameters
[in]typeThe memory allocator type.
[in]argsThe constructor arguments to use.

◆ constructUsingFree()

template<typename T , typename... Args>
T * dart::common::MemoryManager::constructUsingFree ( Args &&...  args)
noexcept

Allocates uninitialized storage using FreeListAllocator and constructs an object of type T to the allocated storage.

◆ constructUsingPool()

template<typename T , typename... Args>
T * dart::common::MemoryManager::constructUsingPool ( Args &&...  args)
noexcept

Allocates uninitialized storage using PoolAllocator and constructs an object of type T to the allocated storage.

◆ deallocate()

void dart::common::MemoryManager::deallocate ( Type  type,
void *  pointer,
size_t  bytes 
)

Deallocates the storage referenced by the pointer p, which must be a pointer obtained by an earlier cal to allocate().

Parameters
[in]typeThe memory allocator type.
[in]pointerPointer obtained from allocate().
[in]bytesThe bytes of the allocated memory.

◆ deallocateUsingFree()

void dart::common::MemoryManager::deallocateUsingFree ( void *  pointer,
size_t  bytes 
)

◆ deallocateUsingPool()

void dart::common::MemoryManager::deallocateUsingPool ( void *  pointer,
size_t  bytes 
)

◆ destroy()

template<typename T >
void dart::common::MemoryManager::destroy ( Type  type,
T *  object 
)
noexcept

Calls the destructor of the object and deallocate the storage.

◆ destroyUsingFree()

template<typename T >
void dart::common::MemoryManager::destroyUsingFree ( T *  pointer)
noexcept

Calls the destructor of the object and deallocate the storage using FreeListAllocator.

◆ destroyUsingPool()

template<typename T >
void dart::common::MemoryManager::destroyUsingPool ( T *  pointer)
noexcept

Calls the destructor of the object and deallocate the storage using PoolAllocator.

◆ getBaseAllocator()

MemoryAllocator & dart::common::MemoryManager::getBaseAllocator ( )

Returns the base allocator.

◆ GetDefault()

MemoryManager & dart::common::MemoryManager::GetDefault ( )
static

Returns the default memory manager.

◆ getFreeListAllocator()

FreeListAllocator & dart::common::MemoryManager::getFreeListAllocator ( )

Returns the free list allocator.

◆ getPoolAllocator()

PoolAllocator & dart::common::MemoryManager::getPoolAllocator ( )

Returns the pool allocator.

◆ hasAllocated()

bool dart::common::MemoryManager::hasAllocated ( void *  pointer,
size_t  size 
) const
noexcept

Returns true if a pointer is allocated by the internal allocator.

◆ print()

void dart::common::MemoryManager::print ( std::ostream &  os = std::cout,
int  indent = 0 
) const

Prints state of the memory manager.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const MemoryManager memoryManager 
)
friend

Prints state of the memory manager.

Member Data Documentation

◆ mBaseAllocator

MemoryAllocator& dart::common::MemoryManager::mBaseAllocator
private

The base allocator to allocate memory chunck.

◆ mFreeListAllocator

FreeListAllocator::Debug dart::common::MemoryManager::mFreeListAllocator
private

The free list allocator.

◆ mPoolAllocator

PoolAllocator::Debug dart::common::MemoryManager::mPoolAllocator
private

The pool allocator.