33 : _data(
std::move(from._data))
35 , _maxSize(from._maxSize)
45 if (_maxSize != _size)
47 _data =
static_cast<T*
>(realloc(_data, _size *
sizeof(T)));
66 std::swap(_data, from._data);
67 std::swap(_size, from._size);
68 std::swap(_maxSize, from._maxSize);
76 if (newSize <= _maxSize)
80 const uint64_t nElems = newSize + (newSize >> 3);
81 const uint64_t nBytes = nElems *
sizeof(T);
82 _data =
static_cast<T*
>(realloc(_data, nBytes));
97 if (newSize <= _maxSize)
100 _data =
static_cast<T*
>(realloc(_data, newSize *
sizeof(T)));
119 const uint64_t oldSize = _size;
121 memcpy(_data + oldSize, data, size *
sizeof(T));
137 memcpy(_data, data, size *
sizeof(T));
144 T* tmpData = buffer._data;
145 const uint64_t tmpSize = buffer._size;
146 const uint64_t tmpMaxSize = buffer._maxSize;
148 buffer._data = _data;
149 buffer._size = _size;
150 buffer._maxSize = _maxSize;
154 _maxSize = tmpMaxSize;
160 LBASSERT(size <= _maxSize);
T * reserve(const uint64_t newSize)
Ensure that the buffer contains at least newSize elements.
Buffer & operator=(const Buffer &from)
Assignment operator, copies data from Buffer.
void append(const T *data, const uint64_t size)
Append elements to the buffer, increasing the size.
bool setSize(const uint64_t size)
Set the size of the buffer without changing its allocation.
void swap(Buffer &buffer)
Swap the buffer contents with another Buffer.
void grow(const uint64_t newSize)
Ensure that the buffer contains at least newSize elements.
Abstraction layer and common utilities for multi-threaded programming.
T * resize(const uint64_t newSize)
Ensure that the buffer contains at least newSize elements.
void replace(const void *data, const uint64_t size)
Replace the existing data with new data.
T * reset(const uint64_t newSize)
Set the buffer size and malloc enough memory.
Buffer()
Construct a new, empty buffer.
A simple memory buffer with some helper functions.
T * pack()
Tighten the allocated memory to the size of the buffer.