57        buffer(
const std::size_t 
size, 
const std::size_t size_of_type = 1)
 
   63                CBEAM_LOG(
"cbeam::container::buffer: Out of RAM (" + std::to_string(
_size) + 
")");
 
   64                throw std::bad_alloc();
 
 
   75        explicit buffer(
const void* address, 
const std::size_t length_of_buffer)
 
   77            uint8_t* new_buffer = (uint8_t*)realloc(
_buffer, length_of_buffer);
 
   80                CBEAM_LOG(
"cbeam::container::buffer::append: Out of RAM (" + std::to_string(
_size) + 
"+" + std::to_string(length_of_buffer) + 
")");
 
   81                throw std::bad_alloc();
 
   85            _size   = length_of_buffer;
 
 
   96        virtual void append(
const void* buffer_to_append, 
const std::size_t length_of_buffer)
 
   98            uint8_t* new_buffer = (uint8_t*)realloc(
_buffer, 
_size + length_of_buffer);
 
  101                CBEAM_LOG(
"cbeam::container::buffer::append: Out of RAM (" + std::to_string(
_size) + 
"+" + std::to_string(length_of_buffer) + 
")");
 
  102                throw std::bad_alloc();
 
  106            std::memcpy(
_buffer + 
_size, buffer_to_append, length_of_buffer);
 
  108            _size += length_of_buffer;
 
 
  112        virtual std::size_t 
size() const noexcept
 
 
  124                    throw cbeam::error::runtime_error(
"cbeam::container::buffer copy assignment operator has been passed a default constructed (therefore invalid) instance");
 
  127                uint8_t* new_buffer = (uint8_t*)realloc(
_buffer, other.
_size);
 
  130                    CBEAM_LOG(
"cbeam::container::buffer::append: Out of RAM (" + std::to_string(other.
_size) + 
")");
 
  131                    throw std::bad_alloc();
 
 
  141        virtual void* 
get() const noexcept
 
 
  158            std::swap(
_buffer, other._buffer);
 
  159            std::swap(
_size, other._size);
 
 
 
 
virtual void * get() const noexcept
return a pointer to the managed memory block
Definition buffer.hpp:141
virtual void swap(buffer &other) noexcept
Swaps the contents of this shared_buffer with another shared_buffer.
Definition buffer.hpp:156
virtual ~buffer() noexcept
Deallocate the memory block.
Definition buffer.hpp:69
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,...
Definition buffer.hpp:96
buffer()=default
Will not create any memory block. Use append to create one or append bytes to an existing one.
buffer(const void *address, const std::size_t length_of_buffer)
Create an instance from a given memory block from address.
Definition buffer.hpp:75
std::size_t _size
Definition buffer.hpp:163
virtual void reset() noexcept
Resets the shared_buffer instance, deallocating the managed memory block.
Definition buffer.hpp:147
uint8_t * _buffer
Definition buffer.hpp:164
buffer(const buffer &other)
Copy construction means that the other buffer is deep copied to construct this instance.
Definition buffer.hpp:90
buffer(const std::size_t size, const std::size_t size_of_type=1)
Create a managed memory block with optional element size.
Definition buffer.hpp:57
virtual buffer & operator=(const buffer &other)
make a deep copy of the other buffer, overwriting the content of this buffer
Definition buffer.hpp:118
virtual std::size_t size() const noexcept
returns the size of the buffer in bytes
Definition buffer.hpp:112
A Cbeam-specific runtime error that also acts like std::runtime_error.
Definition runtime_error.hpp:46
#define CBEAM_LOG(s)
Logs a message using cbeam::logging::log_manager.
Definition log_manager.hpp:124
Offers advanced container types with unique approaches to stability and interprocess sharing....
Definition buffer.hpp:44