libsdr  0.1.0
A simple SDR library
Public Member Functions | Protected Attributes | List of all members
sdr::BufferSet< Scalar > Class Template Reference

A set of buffers, that tracks their usage. More...

#include <buffer.hh>

Inheritance diagram for sdr::BufferSet< Scalar >:
sdr::BufferOwner

Public Member Functions

 BufferSet (size_t N, size_t size)
 Preallocates N buffers of size size. More...
 
virtual ~BufferSet ()
 Destructor, unreferences all buffers. More...
 
bool hasBuffer ()
 Returns true if there is a free buffer. More...
 
Buffer< Scalar > getBuffer ()
 Obtains a free buffer. More...
 
virtual void bufferUnused (const RawBuffer &buffer)
 Callback gets called once the buffer gets unused. More...
 
void resize (size_t numBuffers)
 Resize the buffer set. More...
 

Protected Attributes

size_t _bufferSize
 Size of each buffer. More...
 
std::map< void *, Buffer< Scalar > > _buffers
 Holds a reference to each buffer of the buffer set, referenced by the data pointer of the buffer. More...
 
std::vector< void * > _free_buffers
 A vector of all unused buffers. More...
 

Detailed Description

template<class Scalar>
class sdr::BufferSet< Scalar >

A set of buffers, that tracks their usage.

Frequently it is impossible to predict the time, a buffer will be in use. Instead of allocating a new buffer during runtime, one may allocate several buffer in advance. In this case, it is important to track which buffer is still in use efficiently. This class implements this functionality. A BufferSet pre-allocates several buffers. Once a buffer is requested from the set, it gets marked as "in-use". Once the buffer gets ununsed, it will be marked as "unused" and will be available again.

Constructor & Destructor Documentation

template<class Scalar>
sdr::BufferSet< Scalar >::BufferSet ( size_t  N,
size_t  size 
)
inline

Preallocates N buffers of size size.

template<class Scalar>
virtual sdr::BufferSet< Scalar >::~BufferSet ( )
inlinevirtual

Destructor, unreferences all buffers.

Buffers still in use, are freed once they are dereferenced.

Member Function Documentation

template<class Scalar>
virtual void sdr::BufferSet< Scalar >::bufferUnused ( const RawBuffer buffer)
inlinevirtual

Callback gets called once the buffer gets unused.

Implements sdr::BufferOwner.

template<class Scalar>
Buffer<Scalar> sdr::BufferSet< Scalar >::getBuffer ( )
inline

Obtains a free buffer.

template<class Scalar>
bool sdr::BufferSet< Scalar >::hasBuffer ( )
inline

Returns true if there is a free buffer.

template<class Scalar>
void sdr::BufferSet< Scalar >::resize ( size_t  numBuffers)
inline

Resize the buffer set.

Member Data Documentation

template<class Scalar>
std::map<void *, Buffer<Scalar> > sdr::BufferSet< Scalar >::_buffers
protected

Holds a reference to each buffer of the buffer set, referenced by the data pointer of the buffer.

template<class Scalar>
size_t sdr::BufferSet< Scalar >::_bufferSize
protected

Size of each buffer.

template<class Scalar>
std::vector<void *> sdr::BufferSet< Scalar >::_free_buffers
protected

A vector of all unused buffers.


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