30 : _data(
std::move( from._data ))
32 , _maxSize( from._maxSize )
41 if( _maxSize != _size )
43 _data =
static_cast< T*
>( realloc( _data, _size *
sizeof( T )));
62 std::swap( _data, from._data );
63 std::swap( _size, from._size );
64 std::swap( _maxSize, from._maxSize );
71 if( newSize <= _maxSize )
75 const uint64_t nElems = newSize + (newSize >> 3);
76 const uint64_t nBytes = nElems *
sizeof( T );
77 _data =
static_cast< T*
>( realloc( _data, nBytes ));
90 if( newSize <= _maxSize )
93 _data =
static_cast< T*
>( realloc( _data, newSize *
sizeof( T )));
111 const uint64_t oldSize = _size;
113 memcpy( _data + oldSize, data, size *
sizeof( T ));
128 memcpy( _data, data, size *
sizeof( T ));
134 T* tmpData = buffer._data;
135 const uint64_t tmpSize = buffer._size;
136 const uint64_t tmpMaxSize = buffer._maxSize;
138 buffer._data = _data;
139 buffer._size = _size;
140 buffer._maxSize = _maxSize;
144 _maxSize = tmpMaxSize;
149 LBASSERT( size <= _maxSize );
150 if( 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.