template<typename T, class Allocator>
class Utilities::Buffer< T, Allocator >
A class that manages a buffer of data.
The Buffer class is a template class that manages a buffer of data of type T. It behaves similarly to a std::vector, providing the same kind of accessors, with some key differences: when resizing the buffer, it will use C's realloc() function to resize the buffer, with the guarantee that the data is not moved if the size is the same or less, as POSIX realloc does. Also, the buffer can be created from an external pointer, in which case the buffer will consider the data to be external and will not try to free or reallocate it. This is useful for when the data is for instance a static array or a pointer allocated by a different allocator.
- Template Parameters
-
T | The type of the data in the buffer. |
Allocator | The allocator to use for allocating, deallocating, reallocating and copying the data. The allocator must provide the following functions:
- allocate(size_t size): Allocates a buffer of size bytes and returns a pointer to the buffer.
- deallocate(void* data): Deallocates the buffer pointed to by data.
- reallocate(void* data, size_t size): Reallocates the buffer pointed to by data to size bytes and returns a pointer to the buffer. The behavior needs to be the same as realloc() in C, meaning that if the size is the same or less, the data is not moved. If the size is greater, the data may be moved to a new location. If the size is 0, the data is deallocated and a null pointer is returned.
- copy(void* dest, const void* src, size_t size): Copies size bytes from src to dest. The behavior needs to be the same as memcpy() in C.
|