ocra-recipes
Doxygen documentation for the ocra-recipes repository
Public Types | Public Member Functions | List of all members
ocra::Buffer< T > Class Template Reference

#include <Buffer.h>

Public Types

typedef T value_type
 
typedef T * ptr_type
 

Public Member Functions

 Buffer (size_t size)
 
 ~Buffer ()
 
void resize (size_t size)
 
void reset ()
 
ptr_type allocate (size_t n)
 
size_t size () const
 
size_t freeSize () const
 

Detailed Description

template<class T>
class ocra::Buffer< T >

This class acts as a memory pool for objects of type T. Upon request it returns a pointer to an array of T of size specified by the caller, provided it owns enough memory for that. It allocates contiguous memory blocks and ensures memory release when resizing or dying. Thus, you need not free the memory obtained via this class.

Warning
Don't trust other classes. Don't give them the buffers you obtain here: resize() invalidates them all.

Definition at line 18 of file Buffer.h.

Member Typedef Documentation

template<class T>
typedef T* ocra::Buffer< T >::ptr_type

Definition at line 22 of file Buffer.h.

template<class T>
typedef T ocra::Buffer< T >::value_type

Definition at line 21 of file Buffer.h.

Constructor & Destructor Documentation

template<class T>
ocra::Buffer< T >::Buffer ( size_t  size)
inline

Build an instance of Buffer with a memory buffer for size elements of type T

Definition at line 33 of file Buffer.h.

template<class T>
ocra::Buffer< T >::~Buffer ( )
inline

Definition at line 34 of file Buffer.h.

Member Function Documentation

template<class T>
ptr_type ocra::Buffer< T >::allocate ( size_t  n)
inline

Return the pointer on a free continuous memory block of size n

Exceptions
aruntime_error in case there is not enough memory reserved to fullfill this query.

Definition at line 68 of file Buffer.h.

template<class T>
size_t ocra::Buffer< T >::freeSize ( ) const
inline

Return the size of the reserved memory still free

Definition at line 84 of file Buffer.h.

template<class T>
void ocra::Buffer< T >::reset ( )
inline

Tell the instance to give memory from the beginning of the pool again. All previously given buffers should be considered as invalid

Definition at line 59 of file Buffer.h.

template<class T>
void ocra::Buffer< T >::resize ( size_t  size)
inline

Resize the memory buffer to a size greater or equal to the parameter size. Wether there is really a buffer resizing or not, the previously returned buffer need to be considered as invalid, since calls to allocate subsequent to a resize will return buffers starting from the beginning of the memory pool again.

Definition at line 40 of file Buffer.h.

template<class T>
size_t ocra::Buffer< T >::size ( ) const
inline

Return the size of the reserved memory

Definition at line 78 of file Buffer.h.


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