muu::blob class
#include <muu/blob.h>

Interface for managing chunks of memory.

A blob is an RAII wrapper around a memory allocation intended to be used anywhere you might previously have used something like std::vector<std::byte> or std::unique_ptr<std::byte[]>.

Constructors, destructors, conversion operators

blob() explicit noexcept
Creates an empty blob.
blob(size_t size, const void* src = nullptr, size_t align = {}) explicit
Creates a blob of a fixed size and alignment.
blob(const blob& other)
Copy constructor.
blob(const blob& other, size_t align)
Copy constructor.
blob(blob&& other) noexcept
Move constructor.
operator bool() const explicit noexcept
Returns true if the blob contains data.
~blob() noexcept
Destructor.

Public functions

auto alignment() const -> size_t noexcept
Returns the alignment of the blob's data, in bytes.
auto assign(size_t sz, const void* src, size_t new_align = {}) -> blob&
auto data() -> std::byte* noexcept
Returns a pointer to the blob's data.
auto data() const -> const std::byte* noexcept
Returns a pointer to the blob's data (const overload).
auto operator=(const blob& rhs) -> blob& noexcept
Replaces the contents of the blob by copying from another.
auto operator=(blob&& rhs) -> blob& noexcept
Move-assignment operator.
auto resize(size_t sz) -> blob& noexcept
Resizes the blob, keeping the region of min(newSize, oldSize) intact.
auto size() const -> size_t noexcept
Returns the size of the blob's data, in bytes.

Function documentation

muu::blob::blob(size_t size, const void* src = nullptr, size_t align = {}) explicit

Creates a blob of a fixed size and alignment.

Parameters
size The size of the blob's data, in bytes.
src The source data to copy, if any.
align The alignment of the blob's data. Leave as 0 to use __STDCPP_DEFAULT_NEW_ALIGNMENT__.

muu::blob::blob(const blob& other, size_t align)

Copy constructor.

Parameters
other The blob to copy.
align The alignment of the blob's data. Leave as 0 to copy the source alignment.

blob& muu::blob::assign(size_t sz, const void* src, size_t new_align = {})

Parameters
sz The size of the data.
src The data to copy.
new_align The new alignment to use. Leave as 0 to use __STDCPP_DEFAULT_NEW_ALIGNMENT__.
Returns A reference to the input blob.

Replaces the contents of the blob with the given data.

blob& muu::blob::operator=(const blob& rhs) noexcept

Replaces the contents of the blob by copying from another.

Parameters
rhs The blob to copy.
Returns A reference to the LHS blob.

blob& muu::blob::resize(size_t sz) noexcept

Resizes the blob, keeping the region of min(newSize, oldSize) intact.

Parameters
sz New size.
Returns A reference to the blob.