Go to the documentation of this file.
15 #include <boost/container/small_vector.hpp>
23 template <std::
size_t Alignment>
25 return (
n + ( Alignment - 1 ) ) & ~( Alignment - 1 );
45 template <std::
size_t Alignment = alignof( std::max_align_t ),
typename UpstreamAllocator = std::allocator<std::
byte>>
48 static_assert( std::is_empty_v<UpstreamAllocator>,
"Stateful upstream allocators are not yet supported." );
63 boost::container::small_vector<gsl::span<std::byte>, 1>
m_all_blocks;
78 for (
auto block :
m_all_blocks ) { UpstreamAllocator{}.deallocate( block.data(), block.size() ); }
91 template <std::
size_t ReqAlign>
96 static_assert( ReqAlign <=
alignment,
"Requested alignment too large for this Gaudi::Arena::Monotonic!" );
98 std::size_t const aligned_n = details::align_up<Alignment>(
n );
106 m_current = UpstreamAllocator{}.allocate( next_block_size );
147 [](
std::size_t sum,
auto block ) { return sum + block.size(); } );
std::size_t capacity() const noexcept
Query how much memory is owned by this arena, in bytes.
std::byte * allocate(std::size_t n)
Return an aligned point to n bytes of memory.
Monotonic & operator=(Monotonic &&)=delete
Monotonic(Monotonic const &)=delete
std::byte * m_current_end
One byte past the end of the current block, or nullptr if it doesn't exist.
std::size_t m_next_block_size
Size (in bytes) of the next block to be allocated.
static constexpr std::size_t growth_factor
Approximate factor by which each block is larger than its predecessor.
void reset() noexcept
Signal that this arena may start re-using the memory resources.
Monotonic(std::size_t next_block_size) noexcept
Construct an arena whose first block have approximately the given size.
constexpr std::size_t align_up(std::size_t n)
Monotonic & operator=(Monotonic const &)=delete
boost::container::small_vector< gsl::span< std::byte >, 1 > m_all_blocks
All memory blocks owned by this arena.
A fast memory arena that does not track deallocations.
constexpr void deallocate(std::byte *, std::size_t) noexcept
Deallocations are not tracked, so this is a no-op!
Custom allocator holding a pointer to a generic memory resource.
std::size_t size() const noexcept
Query how much memory was used from this arena, in bytes.
Monotonic(Monotonic &&)=delete
static constexpr std::size_t alignment
std::size_t num_allocations() const noexcept
Query how many allocations this arena has served.
std::size_t m_allocations
Number of allocation requests served by this arena.
std::byte * m_current
Current position in the current block, or nullptr if there is no current block.
std::size_t num_blocks() const noexcept
Query how many blocks of memory this arena owns.