Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
hh::MemoryManager< T > Class Template Reference

Base memory manager. More...

#include "memory_manager.h"

Inheritance diagram for hh::MemoryManager< T >:
Inheritance graph
Collaboration diagram for hh::MemoryManager< T >:
Collaboration graph

Public Member Functions

 MemoryManager (size_t const &capacity)
 Create a memory manager with a certain capacity.
 
 ~MemoryManager () override=default
 Default destructor.
 
std::shared_ptr< AbstractMemoryManagercopy () override
 Default copy method.
 
virtual void initializeMemoryManager ()
 User-definable initialization step for a memory manager.
 
std::shared_ptr< ManagedMemorygetManagedMemory () final
 Get managed memory from the pool.
 
- Public Member Functions inherited from hh::AbstractMemoryManager
 AbstractMemoryManager (size_t const &capacity)
 Only used constructor.
 
virtual ~AbstractMemoryManager ()=default
 Default destructor.
 
int deviceId () const
 Device Id accessor.
 
size_t currentSize ()
 Return the current size of the inside pool.
 
size_t capacity () const
 Capacity accessor.
 
void deviceId (int deviceId)
 Device id setter.
 
void profiler (const std::shared_ptr< NvtxProfiler > &profiler)
 NVTX profiler setter.
 
virtual std::shared_ptr< ManagedMemorygetManagedMemory ()=0
 Get an available managed memory, block if none are available.
 
virtual void recycleMemory (std::shared_ptr< ManagedMemory > const &managedMemory)=0
 Recycle memory.
 
virtual std::shared_ptr< AbstractMemoryManagercopy ()=0
 Virtual copy method used for task duplication and execution pipeline.
 
virtual void initialize ()=0
 Initialize the memory manager.
 
virtual std::string managedType () const =0
 Return the real managed type under the form of a string.
 

Private Member Functions

void recycleMemory (std::shared_ptr< ManagedMemory > const &managedMemory) final
 Recycling mechanism for managed memory.
 
void initialize () final
 Initialize the memory manager.
 
std::string managedType () const final
 Getter to real managed type as string.
 

Additional Inherited Members

- Protected Member Functions inherited from hh::AbstractMemoryManager
std::shared_ptr< NvtxProfiler > const & profiler () const
 Accessor to NVTX profiler.
 
std::unique_ptr< tool::Pool< ManagedMemory > > const & pool () const
 Inside pool accessor.
 
bool isInitialized () const
 Initialized flag accessor.
 
std::mutex & memoryManagerMutex ()
 User api mutex accessor.
 
void initialized ()
 Flag the memory manager has initialized.
 
- Protected Attributes inherited from hh::AbstractMemoryManager
std::mutex memoryManagerMutex_ = {}
 Mutex for user interface.
 

Detailed Description

template<tool::ManageableMemory T>
class hh::MemoryManager< T >

Base memory manager.

Memory manager with default created managed object

Template Parameters
TType managed by the memory manager

Definition at line 37 of file memory_manager.h.

Constructor & Destructor Documentation

◆ MemoryManager()

template<tool::ManageableMemory T>
hh::MemoryManager< T >::MemoryManager ( size_t const &  capacity)
inlineexplicit

Create a memory manager with a certain capacity.

Parameters
capacityCapacity of the memory manager

Definition at line 41 of file memory_manager.h.

◆ ~MemoryManager()

template<tool::ManageableMemory T>
hh::MemoryManager< T >::~MemoryManager ( )
overridedefault

Default destructor.

Member Function Documentation

◆ copy()

template<tool::ManageableMemory T>
std::shared_ptr< AbstractMemoryManager > hh::MemoryManager< T >::copy ( )
inlineoverridevirtual

Default copy method.

Attention
Need to be overloaded by the end user if the memory manager is inherited
Returns
Create another MemoryManager from this

Implements hh::AbstractMemoryManager.

Definition at line 49 of file memory_manager.h.

Here is the call graph for this function:

◆ getManagedMemory()

template<tool::ManageableMemory T>
std::shared_ptr< ManagedMemory > hh::MemoryManager< T >::getManagedMemory ( )
inlinefinalvirtual

Get managed memory from the pool.

Get managed memory from the pool. If the pool is empty, the call will block until a new element get available.

Returns
A managed memory

Implements hh::AbstractMemoryManager.

Definition at line 60 of file memory_manager.h.

Here is the call graph for this function:

◆ initialize()

template<tool::ManageableMemory T>
void hh::MemoryManager< T >::initialize ( )
inlinefinalprivatevirtual

Initialize the memory manager.

Thread safe initialization, fill the pool with default constructed object

Implements hh::AbstractMemoryManager.

Definition at line 87 of file memory_manager.h.

Here is the call graph for this function:

◆ initializeMemoryManager()

template<tool::ManageableMemory T>
virtual void hh::MemoryManager< T >::initializeMemoryManager ( )
inlinevirtual

User-definable initialization step for a memory manager.

Definition at line 54 of file memory_manager.h.

Here is the caller graph for this function:

◆ managedType()

template<tool::ManageableMemory T>
std::string hh::MemoryManager< T >::managedType ( ) const
inlinefinalprivatevirtual

Getter to real managed type as string.

Returns
String of the real managed type

Implements hh::AbstractMemoryManager.

Definition at line 105 of file memory_manager.h.

◆ recycleMemory()

template<tool::ManageableMemory T>
void hh::MemoryManager< T >::recycleMemory ( std::shared_ptr< ManagedMemory > const &  managedMemory)
inlinefinalprivatevirtual

Recycling mechanism for managed memory.

Thread safe recycle that will in sequence:

Implements hh::AbstractMemoryManager.

Definition at line 74 of file memory_manager.h.

Here is the call graph for this function: