RISA
glados::MemoryPool< MemoryManager > Class Template Reference

This class acts as a Memory pool and initializes memory at program initialization. More...

#include <MemoryPool.h>

Inheritance diagram for glados::MemoryPool< MemoryManager >:
Collaboration diagram for glados::MemoryPool< MemoryManager >:

Public Types

using type = glados::Image< MemoryManager >
 

Public Member Functions

auto requestMemory (unsigned int idx) -> type
 Returns memory during data processing to the requesting stage. More...
 
auto returnMemory (type &&img) -> void
 This function reenters the data element in the memory pool. More...
 
auto registerStage (const int &numberOfElements, const size_t &size) -> int
 This function is called at program initialization, when a stage needs memory during data processing. More...
 
auto freeMemory (const unsigned int idx) -> void
 When the classes are destroyed, this functions frees the allocated memory. More...
 
- Public Member Functions inherited from glados::Singleton< MemoryPool< MemoryManager > >
 ~Singleton ()
 

Private Member Functions

 ~MemoryPool ()=default
 
 MemoryPool ()=default
 

Private Attributes

std::vector< std::vector< type > > memoryPool_
 
std::mutex memoryManagerMutex_
 this vector stores the elements for each stage More...
 
std::condition_variable cv_
 the mutex to ensure thread-safety More...
 

Friends

class Singleton< MemoryPool< MemoryManager > >
 

Additional Inherited Members

- Static Public Member Functions inherited from glados::Singleton< MemoryPool< MemoryManager > >
static MemoryPool< MemoryManager > * instance ()
 
- Protected Member Functions inherited from glados::Singleton< MemoryPool< MemoryManager > >
 Singleton ()
 

Detailed Description

template<class MemoryManager>
class glados::MemoryPool< MemoryManager >

This class acts as a Memory pool and initializes memory at program initialization.

At program initialization the requesting stage asks for a given number of elements of a given data type and size. The MemoryPool allocates the memory and provides during data processing, when a stage asks for it.

Definition at line 50 of file MemoryPool.h.

Member Typedef Documentation

template<class MemoryManager >
using glados::MemoryPool< MemoryManager >::type = glados::Image<MemoryManager>

Definition at line 55 of file MemoryPool.h.

Constructor & Destructor Documentation

template<class MemoryManager >
glados::MemoryPool< MemoryManager >::~MemoryPool ( )
privatedefault
template<class MemoryManager >
glados::MemoryPool< MemoryManager >::MemoryPool ( )
privatedefault

Member Function Documentation

template<class MemoryManager >
auto glados::MemoryPool< MemoryManager >::freeMemory ( const unsigned int  idx) -> void
inline

When the classes are destroyed, this functions frees the allocated memory.

Parameters
[in]idxidx stage that requests memory, got an id during registration. This id needs to passed to this function.

Definition at line 133 of file MemoryPool.h.

template<class MemoryManager >
auto glados::MemoryPool< MemoryManager >::registerStage ( const int &  numberOfElements,
const size_t &  size 
) -> int
inline

This function is called at program initialization, when a stage needs memory during data processing.

All stages that need memory need to register in MemoryManager. Stages need to tell, which size of memory they need and how many elements. The MemoryManager then allocates the memory and manages it.

Parameters
[in]numberOfElementsnumber of elements that shall be allocated by the MemoryManager
[in]sizesize of memory that needs to be allocated per element
Returns
identifier, where

Definition at line 110 of file MemoryPool.h.

template<class MemoryManager >
auto glados::MemoryPool< MemoryManager >::requestMemory ( unsigned int  idx) -> type
inline

Returns memory during data processing to the requesting stage.

All stages that are registered in MemoryPool can request memory with this function. If the stage is not registered, an exception will be thrown. Memory allocation occurs only, if stage did not request enough memory during registration. In all other cases no allocation, no copy operations will be performed.

Parameters
[in]idxstage that requests memory, got an id during registration. This id needs to passed to this function.

Definition at line 68 of file MemoryPool.h.

template<class MemoryManager >
auto glados::MemoryPool< MemoryManager >::returnMemory ( type &&  img) -> void
inline

This function reenters the data element in the memory pool.

This function gets an image, e.g. when image gets out of scope and stores it in the memory pool vector, where it originally came from

Parameters
[in]imgImage, that shall be returned into memory pool for reuse

Definition at line 90 of file MemoryPool.h.

Friends And Related Function Documentation

template<class MemoryManager >
friend class Singleton< MemoryPool< MemoryManager > >
friend

Definition at line 52 of file MemoryPool.h.

Member Data Documentation

template<class MemoryManager >
std::condition_variable glados::MemoryPool< MemoryManager >::cv_
private

the mutex to ensure thread-safety

Definition at line 148 of file MemoryPool.h.

template<class MemoryManager >
std::mutex glados::MemoryPool< MemoryManager >::memoryManagerMutex_
mutableprivate

this vector stores the elements for each stage

Definition at line 147 of file MemoryPool.h.

template<class MemoryManager >
std::vector<std::vector<type> > glados::MemoryPool< MemoryManager >::memoryPool_
private

Definition at line 146 of file MemoryPool.h.


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