Go to the documentation of this file.
9 #ifndef EAGINE_MEMORY_BUFFER_POOL_HPP
10 #define EAGINE_MEMORY_BUFFER_POOL_HPP
16 namespace eagine::memory {
27 auto pos = std::lower_bound(
28 _pool.begin(), _pool.end(), req_size, [](
auto& buf,
auto req) {
29 return buf.capacity() < req;
31 if(pos != _pool.end()) {
34 result.resize(req_size);
45 auto pos = std::lower_bound(
49 [](
auto& buf,
auto capacity) { return buf.capacity() < capacity; });
50 _pool.emplace(pos, std::move(used));
54 std::vector<memory::buffer> _pool;
59 #endif // EAGINE_MEMORY_BUFFER_POOL_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Class storing multiple reusable memory buffer instances.
Definition: buffer_pool.hpp:21
auto get(span_size_t req_size=0) -> memory::buffer
Gets a buffer with the specified required size.
Definition: buffer_pool.hpp:26
Reallocatable owning byte buffer.
Definition: buffer.hpp:22
void eat(memory::buffer used)
Returns the specified buffer back to the pool for further reuse.
Definition: buffer_pool.hpp:44
auto capacity() const noexcept -> span_size_t
Returns the capacity of this buffer.
Definition: buffer.hpp:95
auto resize(span_size_t new_size) -> auto &
Resizes the buffer to the specified number of bytes.
Definition: buffer.hpp:114