Equalizer
1.2.1
|
A simple memory buffer with some helper functions. More...
#include <buffer.h>
Public Member Functions | |
Buffer () | |
Construct a new, empty buffer. | |
Buffer (const uint64_t size) | |
Construct a new buffer of the given size. | |
~Buffer () | |
Destruct the buffer. | |
void | clear () |
Flush the buffer, deleting all data. | |
T * | pack () |
Tighten the allocated memory to the size of the buffer. | |
Buffer (Buffer &from) | |
Copy constructor, transfers ownership to new Buffer. | |
const Buffer & | operator= (Buffer &from) |
Assignment operator, copies data from Buffer. | |
T & | operator[] (const uint64_t position) |
Direct access to the element at the given index. | |
const T & | operator[] (const uint64_t position) const |
Direct const access to an element. | |
T * | resize (const uint64_t newSize) |
Ensure that the buffer contains at least newSize elements. | |
void | grow (const uint64_t newSize) |
Ensure that the buffer contains at least newSize elements. | |
T * | reserve (const uint64_t newSize) |
Ensure that the buffer contains at least newSize elements. | |
T * | reset (const uint64_t newSize) |
Set the buffer size and malloc enough memory. | |
void | append (const T *data, const uint64_t size) |
Append elements to the buffer, increasing the size. | |
void | append (const T &element) |
Append one element to the buffer. | |
void | replace (const void *data, const uint64_t size) |
Replace the existing data with new data. | |
void | swap (Buffer &buffer) |
Swap the buffer contents with another Buffer. | |
T * | getData () |
const T * | getData () const |
bool | setSize (const uint64_t size) |
Set the size of the buffer without changing its allocation. | |
uint64_t | getSize () const |
bool | isEmpty () const |
uint64_t | getMaxSize () const |
A simple memory buffer with some helper functions.
For bigger data (>100k) using a std::vector< uint8_t > has a high overhead when resizing (>1ms). This buffer just memcpy's elements, i.e., it should only be used for PODs since the copy constructor or assignment operator is not called on the copied elements. Primarily used for binary data, e.g., in eq::Image. The implementation works like a pool, that is, data is only released when the buffer is deleted or clear() is called.
co::base::Buffer< T >::Buffer | ( | ) | [inline] |
co::base::Buffer< T >::Buffer | ( | const uint64_t | size | ) | [inline] |
co::base::Buffer< T >::~Buffer | ( | ) | [inline] |
co::base::Buffer< T >::Buffer | ( | Buffer< T > & | from | ) | [inline] |
void co::base::Buffer< T >::append | ( | const T * | data, |
const uint64_t | size | ||
) | [inline] |
void co::base::Buffer< T >::append | ( | const T & | element | ) | [inline] |
void co::base::Buffer< T >::clear | ( | ) | [inline] |
Flush the buffer, deleting all data.
Definition at line 54 of file buffer.h.
Referenced by co::base::Buffer< pollfd >::~Buffer().
T* co::base::Buffer< T >::getData | ( | ) | [inline] |
const T* co::base::Buffer< T >::getData | ( | ) | const [inline] |
uint64_t co::base::Buffer< T >::getMaxSize | ( | ) | const [inline] |
uint64_t co::base::Buffer< T >::getSize | ( | ) | const [inline] |
void co::base::Buffer< T >::grow | ( | const uint64_t | newSize | ) | [inline] |
bool co::base::Buffer< T >::isEmpty | ( | ) | const [inline] |
const Buffer& co::base::Buffer< T >::operator= | ( | Buffer< T > & | from | ) | [inline] |
T& co::base::Buffer< T >::operator[] | ( | const uint64_t | position | ) | [inline] |
const T& co::base::Buffer< T >::operator[] | ( | const uint64_t | position | ) | const [inline] |
T* co::base::Buffer< T >::pack | ( | ) | [inline] |
void co::base::Buffer< T >::replace | ( | const void * | data, |
const uint64_t | size | ||
) | [inline] |
Replace the existing data with new data.
Definition at line 181 of file buffer.h.
Referenced by co::base::Buffer< pollfd >::operator=().
T* co::base::Buffer< T >::reserve | ( | const uint64_t | newSize | ) | [inline] |
Ensure that the buffer contains at least newSize elements.
Existing data may be deleted.
Definition at line 135 of file buffer.h.
Referenced by co::base::Buffer< pollfd >::replace(), and co::base::Buffer< pollfd >::reset().
T* co::base::Buffer< T >::reset | ( | const uint64_t | newSize | ) | [inline] |
Set the buffer size and malloc enough memory.
Existing data may be deleted.
Definition at line 155 of file buffer.h.
Referenced by co::base::Buffer< pollfd >::Buffer().
T* co::base::Buffer< T >::resize | ( | const uint64_t | newSize | ) | [inline] |
Ensure that the buffer contains at least newSize elements.
Existing data is retained. The size is set.
Definition at line 102 of file buffer.h.
Referenced by co::base::Buffer< pollfd >::append(), and co::base::Buffer< pollfd >::grow().
bool co::base::Buffer< T >::setSize | ( | const uint64_t | size | ) | [inline] |
Set the size of the buffer without changing its allocation.
This method only modifies the size parameter. If the current allocation of the buffer is too small, it asserts, returns false and does not change the size.
Definition at line 221 of file buffer.h.
Referenced by co::base::Buffer< pollfd >::reset().
void co::base::Buffer< T >::swap | ( | Buffer< T > & | buffer | ) | [inline] |