A simple memory buffer with some helper functions.
More...
#include <buffer.h>
List of all members.
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.
|
| 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.
|
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 |
Detailed Description
template<typename T>
class eq::base::Buffer< T >
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.
Definition at line 37 of file buffer.h.
Constructor & Destructor Documentation
Construct a new, empty buffer.
- Version:
- 1.0
Definition at line 41 of file buffer.h.
Construct a new buffer of the given size.
- Version:
- 1.0
Definition at line 44 of file buffer.h.
Destruct the buffer.
- Version:
- 1.0
Definition at line 48 of file buffer.h.
Copy constructor, transfers ownership to new Buffer.
- Version:
- 1.0
Definition at line 55 of file buffer.h.
Member Function Documentation
template<typename T>
void eq::base::Buffer< T >::append |
( |
const T * |
data, |
|
|
const uint64_t |
size |
|
) |
| [inline] |
Append elements to the buffer, increasing the size.
- Version:
- 1.0
Definition at line 128 of file buffer.h.
Append one element to the buffer.
- Version:
- 1.0
Definition at line 139 of file buffer.h.
- Returns:
- a pointer to the data.
- Version:
- 1.0
Definition at line 173 of file buffer.h.
- Returns:
- a const pointer to the data.
- Version:
- 1.0
Definition at line 176 of file buffer.h.
- Returns:
- the maximum size of the buffer.
- Version:
- 1.0
Definition at line 203 of file buffer.h.
- Returns:
- the current size.
- Version:
- 1.0
Definition at line 197 of file buffer.h.
Ensure that the buffer contains at least newSize elements.
Existing data is retained. The size is increased, if necessary.
- Version:
- 1.0
Definition at line 101 of file buffer.h.
- Returns:
- true if the buffer is empty, false if not.
- Version:
- 1.0
Definition at line 200 of file buffer.h.
Assignment operator, copies data from Buffer.
- Version:
- 1.0
Definition at line 62 of file buffer.h.
template<typename T>
const T& eq::base::Buffer< T >::operator[] |
( |
const uint64_t |
position ) |
const [inline] |
Direct const access to an element.
- Version:
- 1.0
Definition at line 73 of file buffer.h.
Direct access to the element at the given index.
- Version:
- 1.0
Definition at line 69 of file buffer.h.
template<typename T>
void eq::base::Buffer< T >::replace |
( |
const void * |
data, |
|
|
const uint64_t |
size |
|
) |
| [inline] |
Ensure that the buffer contains at least newSize elements.
Existing data may be deleted.
- Returns:
- the new pointer to the first element.
- Version:
- 1.0
Definition at line 114 of file buffer.h.
Referenced by eq::base::Buffer< pollfd >::replace().
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.
- Version:
- 1.0
Definition at line 186 of file buffer.h.
Swap the buffer contents with another Buffer.
- Version:
- 1.0
Definition at line 157 of file buffer.h.
The documentation for this class was generated from the following file: