Lunchbox
1.8.0
|
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 (Buffer &from) | |
Copy constructor, transfers ownership to new Buffer. | |
~Buffer () | |
Destruct the buffer. | |
void | clear () |
Flush the buffer, deleting all data. | |
T * | pack () |
Tighten the allocated memory to the size of the buffer. | |
const Buffer & | operator= (const 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 | replace (const Buffer &from) |
Replace the existing 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 |
uint64_t | getNumBytes () 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.
|
inline |
|
inline |
Construct a new buffer of the given size.
Definition at line 47 of file buffer.h.
References lunchbox::Buffer< T >::reset().
|
inline |
|
inline |
Destruct the buffer.
Definition at line 58 of file buffer.h.
References lunchbox::Buffer< T >::clear().
|
inline |
Append elements to the buffer, increasing the size.
Definition at line 160 of file buffer.h.
References lunchbox::Buffer< T >::resize().
|
inline |
Append one element to the buffer.
Definition at line 171 of file buffer.h.
References lunchbox::Buffer< T >::resize().
|
inline |
Flush the buffer, deleting all data.
Definition at line 61 of file buffer.h.
Referenced by lunchbox::Buffer< T >::~Buffer().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Ensure that the buffer contains at least newSize elements.
Existing data is retained. The size is increased, if necessary.
Definition at line 122 of file buffer.h.
References lunchbox::Buffer< T >::resize().
|
inline |
|
inline |
Assignment operator, copies data from Buffer.
Definition at line 81 of file buffer.h.
References lunchbox::Buffer< T >::replace().
|
inline |
|
inline |
|
inline |
|
inline |
Replace the existing data with new data.
Definition at line 178 of file buffer.h.
References lunchbox::Buffer< T >::reserve().
Referenced by lunchbox::Buffer< T >::operator=().
|
inline |
Replace the existing data.
Definition at line 189 of file buffer.h.
References lunchbox::Buffer< T >::replace().
Referenced by lunchbox::Buffer< T >::replace().
|
inline |
Ensure that the buffer contains at least newSize elements.
Existing data is preserved.
Definition at line 135 of file buffer.h.
Referenced by lunchbox::Buffer< T >::replace(), and lunchbox::Buffer< T >::reset().
|
inline |
Set the buffer size and malloc enough memory.
Existing data may be deleted.
Definition at line 152 of file buffer.h.
References lunchbox::Buffer< T >::reserve(), and lunchbox::Buffer< T >::setSize().
Referenced by lunchbox::Buffer< T >::Buffer().
|
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 lunchbox::Buffer< T >::append(), and lunchbox::Buffer< T >::grow().
|
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 222 of file buffer.h.
Referenced by lunchbox::Buffer< T >::reset().
|
inline |