Go to the documentation of this file.
9 #ifndef EAGINE_MEMORY_BUFFER_HPP
10 #define EAGINE_MEMORY_BUFFER_HPP
12 #include "../assert.hpp"
17 namespace eagine::memory {
33 , _alloc(default_byte_allocator()) {}
37 :
buffer(alignof(long double)) {}
43 , _storage{std::move(temp._storage)}
44 , _alloc{std::move(temp._alloc)} {
53 _storage = std::move(temp._storage);
54 _alloc = std::move(temp._alloc);
69 auto addr() const noexcept {
70 return _storage.
addr();
75 return _storage.
data();
96 return _storage.
size();
104 _reallocate(new_size);
106 EAGINE_ASSERT(_is_ok());
117 EAGINE_ASSERT(_is_ok());
127 if(
size() < new_size) {
130 EAGINE_ASSERT(_is_ok());
160 _alloc.deallocate(std::move(_storage), _align);
166 EAGINE_ASSERT(_is_ok());
167 return {_storage.
begin(), _size};
172 EAGINE_ASSERT(_is_ok());
173 return {_storage.
begin(), _size};
179 owned_block _storage{};
180 shared_byte_allocator _alloc{};
182 auto _is_ok() const noexcept ->
bool {
187 _alloc.do_reallocate(_storage, new_size, _align);
193 #endif // EAGINE_MEMORY_BUFFER_HPP
buffer()
Default constructor.
Definition: buffer.hpp:36
typename block::pointer pointer
Pointer type.
Definition: buffer.hpp:28
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Pointer pointer
The pointer type.
Definition: span.hpp:114
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
constexpr auto begin() const noexcept -> iterator
Returns an interator to the start of the span.
Definition: span.hpp:259
constexpr auto addr() const noexcept -> address_type
Returns the memory address of the start of the span.
Definition: span.hpp:279
basic_block< false > block
Alias for non-const byte memory span.
Definition: block.hpp:27
buffer(buffer &&temp) noexcept
Move constructor.
Definition: buffer.hpp:40
constexpr auto data() const noexcept -> pointer
Returns a pointer to the start of the span.
Definition: span.hpp:254
void free()
Deallocates the buffer.
Definition: buffer.hpp:159
auto enlarge_by(span_size_t inc_size) -> auto &
Enlarges the buffer by the specified number of bytes.
Definition: buffer.hpp:139
typename block::size_type size_type
Buffer size type.
Definition: buffer.hpp:25
auto empty() const noexcept
Indicates that the buffer is empty.
Definition: buffer.hpp:88
Reallocatable owning byte buffer.
Definition: buffer.hpp:22
SizeType size_type
The element count type.
Definition: span.hpp:108
auto clear() -> auto &
Clears the buffer.
Definition: buffer.hpp:149
auto capacity() const noexcept -> span_size_t
Returns the capacity of this buffer.
Definition: buffer.hpp:95
auto operator=(buffer &&temp) noexcept -> buffer &
Move assignment operator.
Definition: buffer.hpp:49
auto data() const noexcept -> pointer
Returns the pointer to the start of the allocated space.
Definition: buffer.hpp:74
constexpr auto size() const noexcept -> size_type
Returns the number of elements in the span.
Definition: span.hpp:246
auto addr() const noexcept
Returns the memory address of the start of the allocated space.
Definition: buffer.hpp:69
auto ensure(span_size_t new_size) -> auto &
Ensure that the buuffer has at least the specified size in bytes.
Definition: buffer.hpp:126
auto size() const noexcept -> span_size_t
Returns the size of the buffer in bytes.
Definition: buffer.hpp:81
auto resize(span_size_t new_size) -> auto &
Resizes the buffer to the specified number of bytes.
Definition: buffer.hpp:114
buffer(span_size_t align)
Constructor with explicit alignment specification.
Definition: buffer.hpp:31
auto reserve(span_size_t new_size) -> auto &
Pre-allocate the specified number of bytes.
Definition: buffer.hpp:102