HTGS  v2.0
The Hybrid Task Graph Scheduler
htgs::MemoryPool< T > Class Template Reference

Creates a pool of memory that allocates/frees MemoryData. More...

#include <htgs/core/memory/MemoryPool.hpp>

Collaboration diagram for htgs::MemoryPool< T >:
Collaboration graph

Public Member Functions

 MemoryPool (size_t queueSize)
 Creates a memory pool with the specified size number of elements. More...
 
 ~MemoryPool ()
 Destructor, deallocates all memory allocated by the MemoryPool.
 
void releaseAllMemory ()
 Releases all memory associated with this memory pool.
 
void fillPool (MemoryData< T > *memory, size_t pipelineId, bool allocate) const
 Fills the pool with memory and specifies the pipelineId to be associated with the MemoryData. More...
 
MemoryPool< T > * copy ()
 Creates a shallow copy of the MemoryPool. More...
 
bool isPoolEmpty () const
 Gets whether the pool is empty or not. More...
 
void emptyPool (bool free) const
 Empties the memory pool releasing memory that had been allocated.
 
m_data_t< T > getMemory () const
 Gets the next piece of memory from the MemoryPool. More...
 
void addMemory (m_data_t< T > o) const
 Adds memory back into the MemoryPool. More...
 

Private Attributes

std::list< m_data_t< T > > * allMemory
 The list of all memory that has been allocated by the memory pool.
 
BlockingQueue< m_data_t< T > > * memoryQueue
 A blocking queue for getting/recycling memory.
 
size_t queueSize
 The size of the memory queue.
 

Detailed Description

template<class T>
class htgs::MemoryPool< T >

Creates a pool of memory that allocates/frees MemoryData.

Currently the memory pool is static and cannot grow dynamically, although dynamic memory allocation can be added in the future, for the GPU it is better to preallocate the memory prior to execution to avoid unnecessary GPU synchronization.

Note
This class should only be called by the HTGS API

Constructor & Destructor Documentation

◆ MemoryPool()

template<class T>
htgs::MemoryPool< T >::MemoryPool ( size_t  queueSize)
inline

Creates a memory pool with the specified size number of elements.

Parameters
queueSizethe number of elements in the memory pool.

Member Function Documentation

◆ addMemory()

template<class T>
void htgs::MemoryPool< T >::addMemory ( m_data_t< T >  o) const
inline

Adds memory back into the MemoryPool.

Parameters
othe memory to be added in.

◆ copy()

template<class T>
MemoryPool<T>* htgs::MemoryPool< T >::copy ( )
inline

Creates a shallow copy of the MemoryPool.

Returns
the copy of the MemoryPool

◆ fillPool()

template<class T>
void htgs::MemoryPool< T >::fillPool ( MemoryData< T > *  memory,
size_t  pipelineId,
bool  allocate 
) const
inline

Fills the pool with memory and specifies the pipelineId to be associated with the MemoryData.

Parameters
memorythe memory that is allocated.
pipelineIdthe pipelineId associated with the memory.
allocatewhether to allocate the memory before adding

◆ getMemory()

template<class T>
m_data_t<T> htgs::MemoryPool< T >::getMemory ( ) const
inline

Gets the next piece of memory from the MemoryPool.

Returns
the next memory in the MemoryPool

◆ isPoolEmpty()

template<class T>
bool htgs::MemoryPool< T >::isPoolEmpty ( ) const
inline

Gets whether the pool is empty or not.

Returns
whether the pool is empty
Return values
TRUEif the pool is empty
FALSEif the pool is not empty

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