Manages memory a byte buffer, offering dynamic appending. This class is designed for scenarios where performance and control are crucial, such as in systems with dynamic memory requirements or real-time constraints. It uses malloc and free for efficient resizing of memory blocks without initialization overhead, as it internally uses the plain data type uint8_t.
More...
#include <buffer.hpp>
|
| buffer ()=default |
| Will not create any memory block. Use append to create one or append bytes to an existing one.
|
|
| buffer (const std::size_t size, const std::size_t size_of_type=1) |
| Create a managed memory block with optional element size.
|
|
virtual | ~buffer () noexcept |
| Deallocate the memory block.
|
|
| buffer (const void *address, const std::size_t length_of_buffer) |
| Create an instance from a given memory block from address.
|
|
| buffer (const buffer &other) |
| Copy construction means that the other buffer is deep copied to construct this instance.
|
|
virtual void | append (const void *buffer_to_append, const std::size_t length_of_buffer) |
| append the given buffer to the end of the current buffer. If there is no current buffer yet, it will be allocated. Memory will be copied if required, otherwise expanded.
|
|
virtual std::size_t | size () const noexcept |
| returns the size of the buffer in bytes
|
|
virtual buffer & | operator= (const buffer &other) |
| make a deep copy of the other buffer, overwriting the content of this buffer
|
|
virtual void * | get () const noexcept |
| return a pointer to the managed memory block
|
|
virtual void | reset () noexcept |
| Resets the shared_buffer instance, deallocating the managed memory block.
|
|
virtual void | swap (buffer &other) noexcept |
| Swaps the contents of this shared_buffer with another shared_buffer.
|
|
Manages memory a byte buffer, offering dynamic appending. This class is designed for scenarios where performance and control are crucial, such as in systems with dynamic memory requirements or real-time constraints. It uses malloc and free for efficient resizing of memory blocks without initialization overhead, as it internally uses the plain data type uint8_t.
◆ buffer() [1/4]
cbeam::container::buffer::buffer |
( |
| ) |
|
|
default |
Will not create any memory block. Use append
to create one or append bytes to an existing one.
◆ buffer() [2/4]
cbeam::container::buffer::buffer |
( |
const std::size_t | size, |
|
|
const std::size_t | size_of_type = 1 ) |
|
inline |
Create a managed memory block with optional element size.
- Parameters
-
size | Number of elements to allocate. Defaults to allocating single bytes if size_of_type is not specified. |
size_of_type | (Optional) Byte size of each element to allocate. Defaults to 1 if not specified, allowing for byte-sized handling similar to std::memset. |
◆ ~buffer()
virtual cbeam::container::buffer::~buffer |
( |
| ) |
|
|
inlinevirtualnoexcept |
Deallocate the memory block.
◆ buffer() [3/4]
cbeam::container::buffer::buffer |
( |
const void * | address, |
|
|
const std::size_t | length_of_buffer ) |
|
inlineexplicit |
Create an instance from a given memory block from address.
◆ buffer() [4/4]
cbeam::container::buffer::buffer |
( |
const buffer & | other | ) |
|
|
inline |
Copy construction means that the other buffer is deep copied to construct this instance.
◆ append()
virtual void cbeam::container::buffer::append |
( |
const void * | buffer_to_append, |
|
|
const std::size_t | length_of_buffer ) |
|
inlinevirtual |
append the given buffer to the end of the current buffer. If there is no current buffer yet, it will be allocated. Memory will be copied if required, otherwise expanded.
◆ get()
virtual void * cbeam::container::buffer::get |
( |
| ) |
const |
|
inlinevirtualnoexcept |
return a pointer to the managed memory block
◆ operator=()
virtual buffer & cbeam::container::buffer::operator= |
( |
const buffer & | other | ) |
|
|
inlinevirtual |
◆ reset()
virtual void cbeam::container::buffer::reset |
( |
| ) |
|
|
inlinevirtualnoexcept |
◆ size()
virtual std::size_t cbeam::container::buffer::size |
( |
| ) |
const |
|
inlinevirtualnoexcept |
returns the size of the buffer in bytes
◆ swap()
virtual void cbeam::container::buffer::swap |
( |
buffer & | other | ) |
|
|
inlinevirtualnoexcept |
◆ _buffer
uint8_t* cbeam::container::buffer::_buffer {nullptr} |
|
protected |
◆ _size
std::size_t cbeam::container::buffer::_size {0} |
|
protected |
The documentation for this class was generated from the following file: