ngscopeclient 0.1-dev+51fbda87c
Public Member Functions | Protected Attributes | List of all members

Thread safe memory pool for reusing Waveform objects. More...

#include <WaveformPool.h>

Public Member Functions

 WaveformPool (size_t maxSize=16)
 Creates a waveform pool. More...
 
void Add (WaveformBase *w)
 Adds a new waveform to the pool if there's sufficient free slots in the pool. More...
 
WaveformBaseGet ()
 Attempts to get a waveform from the pool. More...
 
bool clear ()
 Free all waveforms in the pool to reclaim memory. More...
 

Protected Attributes

size_t m_maxSize
 Maximum number of waveforms to store in the pool.
 
std::mutex m_mutex
 Mutex for synchronizing access to m_waveforms across threads.
 
std::list< WaveformBase * > m_waveforms
 The list of free waveforms.
 

Detailed Description

Thread safe memory pool for reusing Waveform objects.

Allocating and freeing GPU memory can be an expensive operation so it's usually preferable to recycle existing Waveform objects if possible.

Constructor & Destructor Documentation

◆ WaveformPool()

WaveformPool::WaveformPool ( size_t  maxSize = 16)
inline

Creates a waveform pool.

Parameters
maxSizeMaximum number of waveforms to store in the pool

Member Function Documentation

◆ Add()

void WaveformPool::Add ( WaveformBase w)
inline

Adds a new waveform to the pool if there's sufficient free slots in the pool.

If the pool is already full the waveform is destroyed.

Parameters
wThe waveform to add

◆ clear()

bool WaveformPool::clear ( )
inline

Free all waveforms in the pool to reclaim memory.

Returns
True if memory was freed, false if pool was empty to begin with

◆ Get()

WaveformBase * WaveformPool::Get ( )
inline

Attempts to get a waveform from the pool.

Returns
The waveform, if one is available. Returns nullptr if the pool is empty.

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