Lunchbox
1.16.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
|
A simple memory buffer with some helper functions. More...
#include <buffer.h>
Public Member Functions | |
Buffer () | |
Construct a new, empty buffer. More... | |
Buffer (const uint64_t size) | |
Construct a new buffer of the given size. More... | |
Buffer (const Buffer &from) | |
Copy constructor, copies data to new Buffer. More... | |
Buffer (Buffer &&from) | |
Move constructor, transfers data to new Buffer. More... | |
~Buffer () | |
Destruct the buffer. More... | |
void | clear () |
Flush the buffer, deleting all data. More... | |
T * | pack () |
Tighten the allocated memory to the size of the buffer. More... | |
Buffer & | operator= (const Buffer &from) |
Assignment operator, copies data from Buffer. More... | |
Buffer & | operator= (Buffer &&from) |
Move operator, transfers ownership. More... | |
T & | operator[] (const uint64_t position) |
Direct access to the element at the given index. More... | |
const T & | operator[] (const uint64_t position) const |
Direct const access to an element. More... | |
T * | resize (const uint64_t newSize) |
Ensure that the buffer contains at least newSize elements. More... | |
void | grow (const uint64_t newSize) |
Ensure that the buffer contains at least newSize elements. More... | |
T * | reserve (const uint64_t newSize) |
Ensure that the buffer contains at least newSize elements. More... | |
T * | reset (const uint64_t newSize) |
Set the buffer size and malloc enough memory. More... | |
void | setZero () |
Set the buffer content to 0. More... | |
void | append (const T *data, const uint64_t size) |
Append elements to the buffer, increasing the size. More... | |
void | append (const T &element) |
Append one element to the buffer. More... | |
void | replace (const void *data, const uint64_t size) |
Replace the existing data with new data. More... | |
void | replace (const Buffer &from) |
Replace the existing data. More... | |
void | swap (Buffer &buffer) |
Swap the buffer contents with another Buffer. More... | |
T * | getData () |
const T * | getData () const |
bool | setSize (const uint64_t size) |
Set the size of the buffer without changing its allocation. More... | |
uint64_t | getSize () const |
uint64_t | getNumBytes () const |
bool | isEmpty () const |
uint64_t | getMaxSize () const |
A simple memory buffer with some helper functions.
std::vector does not implement optimizations for growing bitwise-movable vectors, i.e., it copy-constructs each element on growth.
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 |
Construct a new, empty buffer.
Definition at line 48 of file buffer.h.
Referenced by lunchbox::Buffer< T >::Buffer().
|
inlineexplicit |
Construct a new buffer of the given size.
Definition at line 56 of file buffer.h.
References lunchbox::Buffer< T >::Buffer(), and lunchbox::Buffer< T >::reset().
lunchbox::Buffer< T >::Buffer | ( | const Buffer< T > & | from | ) |
Copy constructor, copies data to new Buffer.
Definition at line 22 of file buffer.ipp.
References lunchbox::Buffer< T >::isEmpty().
lunchbox::Buffer< T >::Buffer | ( | Buffer< T > && | from | ) |
Move constructor, transfers data to new Buffer.
Definition at line 32 of file buffer.ipp.
|
inline |
Destruct the buffer.
Definition at line 71 of file buffer.h.
References lunchbox::Buffer< T >::clear().
void lunchbox::Buffer< T >::append | ( | const T * | data, |
const uint64_t | size | ||
) |
Append elements to the buffer, increasing the size.
Definition at line 114 of file buffer.ipp.
References lunchbox::Buffer< T >::resize().
Referenced by lunchbox::Buffer< T >::append(), and lunchbox::Buffer< T >::setZero().
void lunchbox::Buffer< T >::append | ( | const T & | element | ) |
Append one element to the buffer.
Definition at line 125 of file buffer.ipp.
References lunchbox::Buffer< T >::append().
|
inline |
Flush the buffer, deleting all data.
Definition at line 73 of file buffer.h.
References lunchbox::Buffer< T >::operator=(), and lunchbox::Buffer< T >::pack().
Referenced by lunchbox::Buffer< T >::~Buffer().
|
inline |
|
inline |
Definition at line 163 of file buffer.h.
References lunchbox::Buffer< T >::setSize().
|
inline |
|
inline |
|
inline |
void lunchbox::Buffer< T >::grow | ( | const uint64_t | newSize | ) |
Ensure that the buffer contains at least newSize elements.
Existing data is retained. The size is increased, if necessary.
Definition at line 88 of file buffer.ipp.
References lunchbox::Buffer< T >::resize().
Referenced by lunchbox::Buffer< T >::operator[]().
|
inline |
Definition at line 179 of file buffer.h.
Referenced by lunchbox::Buffer< T >::Buffer().
Buffer< T > & lunchbox::Buffer< T >::operator= | ( | const Buffer< T > & | from | ) |
Assignment operator, copies data from Buffer.
Definition at line 54 of file buffer.ipp.
References lunchbox::Buffer< T >::replace().
Referenced by lunchbox::Buffer< T >::clear().
Buffer< T > & lunchbox::Buffer< T >::operator= | ( | Buffer< T > && | from | ) |
|
inline |
|
inline |
Direct const access to an element.
Definition at line 103 of file buffer.h.
References lunchbox::Buffer< T >::grow(), lunchbox::Buffer< T >::reserve(), lunchbox::Buffer< T >::reset(), and lunchbox::Buffer< T >::resize().
T * lunchbox::Buffer< T >::pack | ( | ) |
Tighten the allocated memory to the size of the buffer.
Definition at line 43 of file buffer.ipp.
Referenced by lunchbox::Buffer< T >::clear().
void lunchbox::Buffer< T >::replace | ( | const void * | data, |
const uint64_t | size | ||
) |
Replace the existing data with new data.
Definition at line 131 of file buffer.ipp.
References lunchbox::Buffer< T >::reserve().
Referenced by lunchbox::Buffer< T >::operator=(), and lunchbox::Buffer< T >::setZero().
|
inline |
Replace the existing data.
Definition at line 156 of file buffer.h.
References lunchbox::Buffer< T >::replace(), and lunchbox::Buffer< T >::swap().
Referenced by lunchbox::Buffer< T >::replace().
T * lunchbox::Buffer< T >::reserve | ( | const uint64_t | newSize | ) |
Ensure that the buffer contains at least newSize elements.
Existing data is preserved.
Definition at line 95 of file buffer.ipp.
Referenced by lunchbox::Buffer< T >::operator[](), lunchbox::Buffer< T >::replace(), and lunchbox::Buffer< T >::reset().
T * lunchbox::Buffer< T >::reset | ( | const uint64_t | newSize | ) |
Set the buffer size and malloc enough memory.
Existing data may be deleted.
Definition at line 106 of file buffer.ipp.
References lunchbox::Buffer< T >::reserve(), and lunchbox::Buffer< T >::setSize().
Referenced by lunchbox::Buffer< T >::Buffer(), and lunchbox::Buffer< T >::operator[]().
T * lunchbox::Buffer< T >::resize | ( | const uint64_t | newSize | ) |
Ensure that the buffer contains at least newSize elements.
Existing data is retained. The size is set.
Definition at line 73 of file buffer.ipp.
Referenced by lunchbox::Buffer< T >::append(), lunchbox::Buffer< T >::grow(), and lunchbox::Buffer< T >::operator[]().
bool lunchbox::Buffer< T >::setSize | ( | const uint64_t | size | ) |
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 158 of file buffer.ipp.
Referenced by lunchbox::Buffer< T >::getData(), and lunchbox::Buffer< T >::reset().
|
inline |
Set the buffer content to 0.
Definition at line 145 of file buffer.h.
References lunchbox::Buffer< T >::append(), and lunchbox::Buffer< T >::replace().
void lunchbox::Buffer< T >::swap | ( | Buffer< T > & | buffer | ) |
Swap the buffer contents with another Buffer.
Definition at line 142 of file buffer.ipp.
Referenced by lunchbox::Buffer< T >::replace().