Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
hh::MemoryData< ManagedMemory > Class Template Reference

Memory data interface to use a data type in a Memory manager (AbstractMemoryManager or StaticMemoryManager) More...

#include "memory_data.h"

Inheritance diagram for hh::MemoryData< ManagedMemory >:
Inheritance graph
Collaboration diagram for hh::MemoryData< ManagedMemory >:
Collaboration graph

Public Member Functions

 MemoryData ()=default
 Default constructor.
 
virtual ~MemoryData ()=default
 Default destructor.
 
AbstractMemoryManager< ManagedMemory > * memoryManager () const
 Memory manager accessor. More...
 
void memoryManager (AbstractMemoryManager< ManagedMemory > *memoryManager)
 Memory manager setter. More...
 
void returnToMemoryManager ()
 Return the data to the memory manager.
 
virtual void used ()
 Mechanism to update the state of the data.
 
virtual bool canBeRecycled ()
 Accessor to test if the data can be recycle and sent bask to the Pool, true by default. More...
 
virtual void recycle ()
 Mechanism to recycle data. More...
 

Private Attributes

AbstractMemoryManager< ManagedMemory > * memoryManager_ = nullptr
 Link to the Memory Manager.
 

Detailed Description

template<class ManagedMemory>
class hh::MemoryData< ManagedMemory >

Memory data interface to use a data type in a Memory manager (AbstractMemoryManager or StaticMemoryManager)

To declare a data A or B using the interface MemoryData, it can be written as:

class A : public MemoryData<A>{};
//Or
template <class T>
class B : public MemoryData<B<T>>{};

The data will be served from the pool to the task through the AbstractMemoryManager, and can be return with MemoryData::returnToMemoryManager(). When returned, the MemoryData::used() and MemoryData::canBeRecycled() are called. If MemoryData::canBeRecycled() returns true, MemoryData::recycle() is called and it is returned to the pool and made available by its AbstractMemoryManager

Virtual Functions
MemoryData::used MemoryData::canBeRecycled MemoryData::recycle
Template Parameters
ManagedMemorytype of data to managed

Definition at line 50 of file memory_data.h.

Member Function Documentation

◆ canBeRecycled()

template<class ManagedMemory >
virtual bool hh::MemoryData< ManagedMemory >::canBeRecycled ( )
inlinevirtual

Accessor to test if the data can be recycle and sent bask to the Pool, true by default.

Returns
True if the data can be sent to the Pool, else False

Definition at line 76 of file memory_data.h.

◆ memoryManager() [1/2]

template<class ManagedMemory >
AbstractMemoryManager<ManagedMemory>* hh::MemoryData< ManagedMemory >::memoryManager ( ) const
inline

Memory manager accessor.

Returns
Memory manager

Definition at line 62 of file memory_data.h.

◆ memoryManager() [2/2]

template<class ManagedMemory >
void hh::MemoryData< ManagedMemory >::memoryManager ( AbstractMemoryManager< ManagedMemory > *  memoryManager)
inline

Memory manager setter.

Parameters
memoryManagerMemory manager to set

Definition at line 66 of file memory_data.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recycle()

template<class ManagedMemory >
virtual void hh::MemoryData< ManagedMemory >::recycle ( )
inlinevirtual

Mechanism to recycle data.

If the ManagedMemory type uses user-defined allocations, then recycle is an appropriate place to deallocate the user-allocated data. It will be called only once before it is sent back to the pool.

Attention
If a StaticMemoryManager is used, then deallocation should be done within the destructor to match any allocations done within the constructor. (see StaticMemoryManager for more details)

Definition at line 83 of file memory_data.h.


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