eckit::Buffer class

Simple class to implement memory buffers.

Derived classes

class CountedBuffer

Constructors, destructors, conversion operators

Buffer(size_t size = 0) explicit
Buffer(const std::string& s) explicit
Buffer(const void* src, size_t size)
Buffer(Buffer&& rhs) noexcept
Move constructor. Note that rhs is not guaranteed to be valid!
~Buffer()
operator char*()
operator const char*() const
operator void*()
operator const void*() const

Public functions

auto operator=(Buffer&& rhs) -> Buffer& noexcept
Move assignment. Note that rhs is not guaranteed to be valid!
auto data() -> void*
auto data() const -> const void*
auto size() const -> size_t
void zero()
Zero content of buffer.
void resize(size_t newSize, bool preserveData = false)
void copy(const void*, size_t size, size_t pos = 0)

Function documentation

eckit::Buffer::Buffer(size_t size = 0) explicit

Parameters
size in bytes of the buffer.

Creates a buffer with 'size' many bytes.

eckit::Buffer::Buffer(const std::string& s) explicit

Parameters
s content of buffer, including null-terminator

Creates a buffer from the string s. NOTE: the buffer will contain the string as a zero terminated c-string. I.e. the resulting size of buffer is s.size() + 1

eckit::Buffer::Buffer(const void* src, size_t size)

Parameters
src to copy bytes from
size of data

Creates buffer with initial content

size_t eckit::Buffer::size() const

Returns buffer size in bytes

Returns size of the buffer in bytes Note: The actual allocation held by this buffer may be larger if the buffer has been resized with 'preserveData' set to a smaller size than before.

void eckit::Buffer::resize(size_t newSize, bool preserveData = false)

Resizes the buffer to newSize. When 'preserveData' is set:

  • Buffer will still hold the data contained before resize() was called.
  • If 'newSize' is smaller than the current 'size' the data will be truncated. With unset 'preserveData' the contents of the buffer will be discarded.

void eckit::Buffer::copy(const void*, size_t size, size_t pos = 0)

Copy data of given size (bytes) into buffer at given position

This website is beyond its original expiry date and the content may be out of date. The site owner has been notified and may choose to extend the expiry date and remove this banner. If you have any questions about this, please visit our support portal.