|
FE 0.8.0
Header-only C++ frontend library
|
An arena pre-allocates so-called pages of size Arena::page_size_. More...
#include <fe/arena.h>
Classes | |
| class | MemoryResource |
| A memory resource bridge in order to use this Arena for pmr containers. More... | |
| struct | Allocator |
| An allocator in order to use this Arena for containers. More... | |
| struct | Deleter |
Public Types | |
| template<class T> | |
| using | Ptr = std::unique_ptr<T, Deleter<T>> |
| using | State = std::pair<size_t, size_t> |
Public Member Functions | |
Construction | |
| Arena (const Arena &)=delete | |
| Arena (size_t page_size=Default_Page_Size) | |
| Arena (Arena &&other) noexcept | |
| Arena & | operator= (Arena)=delete |
| template<class T> | |
| constexpr Allocator< T > | allocator () noexcept |
| Create Allocator from Arena. | |
| std::pmr::memory_resource * | resource () noexcept |
| const std::pmr::memory_resource * | resource () const noexcept |
| template<class T, class... Args> | |
| constexpr Ptr< T > | mk (Args &&... args) |
| This is a std::unique_ptr that uses the Arena under the hood and whose Deleter will only invoke the destructor but not delete anything; memory will be released upon destruction of the Arena. | |
Allocate | |
| constexpr void * | allocate (size_t num_bytes, size_t align) |
Get n bytes of fresh memory. | |
| template<class T> | |
| constexpr T * | allocate (size_t num_elems) |
Deallocate | |
Deallocate memory again in reverse order. Use like this: auto state = arena.state();
auto ptr = arena.allocate(n);
| |
| constexpr void | deallocate (size_t num_bytes) noexcept |
Removes num_bytes again. | |
| State | state () const noexcept |
| void | deallocate (State state) noexcept |
Static Public Member Functions | |
| static constexpr size_t | align (size_t i, size_t a) noexcept |
Align i to a. | |
Static Public Attributes | |
| static constexpr size_t | Default_Page_Size = 1024 * 1024 |
| 1MB. | |
Friends | |
| void | swap (Arena &a1, Arena &a2) noexcept |
An arena pre-allocates so-called pages of size Arena::page_size_.
You can use Arena::allocate to obtain memory from this. When a page runs out of memory, the next page will be (pre-)allocated. You cannot directly release memory obtained via this method. Instead, all memory acquired via this Arena will be released as soon as this Arena will be destroyed. As an exception, you can Arena::deallocate memory that has just been acquired.
| using fe::Arena::Ptr = std::unique_ptr<T, Deleter<T>> |
| using fe::Arena::State = std::pair<size_t, size_t> |
|
delete |
References Arena().
Referenced by fe::Arena::Allocator< T >::Allocator(), Arena(), Arena(), fe::Arena::MemoryResource::MemoryResource(), operator=(), and swap.
|
inlineexplicit |
Definition at line 92 of file arena.h.
References Default_Page_Size.
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenodiscardconstexpr |
Get n bytes of fresh memory.
Definition at line 131 of file arena.h.
References align().
Referenced by allocate(), and mk().
|
inlinenodiscardconstexpr |
Definition at line 147 of file arena.h.
References allocate().
|
inlineconstexprnoexcept |
Definition at line 104 of file arena.h.
Referenced by fe::Arena::Allocator< T >::Allocator().
|
inlineconstexprnoexcept |
|
inlinenoexcept |
|
inlineconstexpr |
This is a std::unique_ptr that uses the Arena under the hood and whose Deleter will only invoke the destructor but not delete anything; memory will be released upon destruction of the Arena.
Use like this:
Definition at line 121 of file arena.h.
References allocate().
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 108 of file arena.h.
Referenced by fe::Arena::MemoryResource::do_is_equal().
|
inlinenodiscardnoexcept |
Definition at line 168 of file arena.h.
Referenced by deallocate().
|
staticconstexpr |