FE 0.6.0
A header-only C++ library for writing frontends
|
An arena pre-allocates so-called pages of size Arena::page_size_. More...
#include <fe/arena.h>
Classes | |
struct | Allocator |
struct | Deleter |
Public Member Functions | |
Allocator | |
An allocator in order to use this Arena for containers. Construct it via Arena::allocator. | |
template<class T > | |
Allocator< T > | allocator () |
Create Allocator from Arena. | |
Construction/Destruction | |
Arena (size_t page_size=Default_Page_Size) | |
Arena (const Arena &)=delete | |
Arena (Arena &&other) noexcept | |
Arena & | operator= (Arena)=delete |
Allocate | |
Arena & | align (size_t a) |
Align next allocate(size_t) to a . | |
void * | allocate (size_t num_bytes) |
Get n bytes of fresh memory. | |
template<class T > | |
T * | allocate (size_t num_elems) |
Static Public Attributes | |
static constexpr size_t | Default_Page_Size = 1024 * 1024 |
1MB. | |
Friends | |
void | swap (Arena &a1, Arena &a2) noexcept |
Smart Pointer | |
This is a std::unique_ptr that uses the Arena under the hood and whose deleter will only invoke the destructor but not Use like this: auto ptr = arena.mk<Foo>(a, b, c); // new Foo(a, b, c) placed into arena
| |
template<class T > | |
using | Ptr = std::unique_ptr<T, Deleter<T>> |
template<class T , class... Args> | |
Ptr< T > | mk (Args &&... args) |
Deallocate | |
Deallocate memory again in reverse order. | |
using | State = std::pair<size_t, size_t> |
Goes back to state in Arena. | |
void | deallocate (size_t num_bytes) |
State | state () const |
void | deallocate (State state) |
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 just as been acquired.
using fe::Arena::Ptr = std::unique_ptr<T, Deleter<T>> |
using fe::Arena::State = std::pair<size_t, size_t> |
|
inline |
|
delete |
|
inlinenoexcept |
|
inline |
Align next allocate(size_t) to a
.
Definition at line 92 of file arena.h.
Referenced by allocate(), and fe::SymPool::sym().
|
inlinenodiscard |
Get n
bytes of fresh memory.
Definition at line 95 of file arena.h.
Referenced by allocate(), fe::Arena::Allocator< T >::allocate(), mk(), and fe::SymPool::sym().
|
inlinenodiscard |
Definition at line 106 of file arena.h.
References align(), and allocate().
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 68 of file arena.h.
References allocate().
|
inline |
Definition at line 127 of file arena.h.
Referenced by deallocate(), and fe::SymPool::sym().
|
staticconstexpr |