4#ifndef WPI_MEMORY_TEMPORARY_ALLOCATOR_HPP_INCLUDED
5#define WPI_MEMORY_TEMPORARY_ALLOCATOR_HPP_INCLUDED
13#if WPI_MEMORY_TEMPORARY_STACK_MODE >= 2
21 class temporary_allocator;
22 class temporary_stack;
48 std::
size_t block_size_;
53 class temporary_stack_list;
55#if WPI_MEMORY_TEMPORARY_STACK_MODE >= 2
68 std::atomic<bool> in_use_;
70 friend temporary_stack_list;
73 static class temporary_allocator_dtor_t
76 temporary_allocator_dtor_t() noexcept;
77 ~temporary_allocator_dtor_t() noexcept;
78 } temporary_allocator_dtor;
111 return stack_.get_allocator().set_growth_tracker(t);
117 return stack_.get_allocator().get_growth_tracker();
123 explicit temporary_stack(std::size_t initial_size) : stack_(initial_size), top_(nullptr)
130 return stack_.next_capacity();
135 :
detail::temporary_stack_list_node(i), stack_(initial_size), top_(nullptr)
139 using marker = detail::temporary_stack_impl::marker;
141 marker top() const noexcept
146 void unwind(marker m)
noexcept
151 detail::temporary_stack_impl stack_;
152 temporary_allocator* top_;
155 friend temporary_allocator;
156 friend memory_stack_raii_unwind<temporary_stack>;
157 friend detail::temporary_stack_list;
176 static constexpr std::size_t default_stack_size = 4096u;
237 void* allocate(
std::
size_t size,
std::
size_t alignment);
242 bool is_active() const noexcept;
249 void shrink_to_fit() noexcept;
255 return unwind_.get_stack();
264 template <
class Allocator>
265 class allocator_traits;
280 std::size_t alignment)
282 detail::check_allocation_size<bad_node_size>(size,
283 [&] {
return max_node_size(state); },
285 "::temporary_allocator",
287 return state.allocate(size, alignment);
292 std::size_t alignment)
294 return allocate_node(state, count * size, alignment);
301 std::size_t)
noexcept
306 std::size_t)
noexcept
315 return state.get_stack().next_capacity();
320 return max_node_size(state);
328 return std::size_t(-1);
static std::size_t max_node_size(const allocator_type &state) noexcept
Definition temporary_allocator.hpp:313
static void * allocate_array(allocator_type &state, std::size_t count, std::size_t size, std::size_t alignment)
Definition temporary_allocator.hpp:291
std::true_type is_stateful
Definition temporary_allocator.hpp:276
static void * allocate_node(allocator_type &state, std::size_t size, std::size_t alignment)
Definition temporary_allocator.hpp:279
static std::size_t max_array_size(const allocator_type &state) noexcept
Definition temporary_allocator.hpp:318
static void deallocate_array(const allocator_type &, void *, std::size_t, std::size_t, std::size_t) noexcept
Definition temporary_allocator.hpp:305
static void deallocate_node(const allocator_type &, void *, std::size_t, std::size_t) noexcept
Definition temporary_allocator.hpp:300
static std::size_t max_alignment(const allocator_type &) noexcept
Definition temporary_allocator.hpp:326
The default specialization of the allocator_traits for a RawAllocator.
Definition allocator_traits.hpp:292
Definition temporary_allocator.hpp:27
std::size_t next_block_size() const noexcept
Definition temporary_allocator.hpp:35
void(*)(std::size_t size) growth_tracker
Definition temporary_allocator.hpp:40
temporary_block_allocator(std::size_t block_size) noexcept
growth_tracker set_growth_tracker(growth_tracker t) noexcept
growth_tracker get_growth_tracker() noexcept
void deallocate_block(memory_block block)
memory_block allocate_block()
Definition temporary_allocator.hpp:81
temporary_stack_list_node(int) noexcept
Definition temporary_allocator.hpp:85
~temporary_stack_list_node() noexcept
Definition temporary_allocator.hpp:87
temporary_stack_list_node() noexcept
Definition temporary_allocator.hpp:83
Simple utility that automatically unwinds a Stack to a previously saved location.
Definition memory_stack.hpp:282
Alias template for an STL container that uses a certain RawAllocator.
Definition container.hpp:184
A stateful RawAllocator that handles temporary allocations.
Definition temporary_allocator.hpp:220
temporary_allocator(temporary_stack &stack)
~temporary_allocator() noexcept
Manually takes care of the lifetime of the per-thread temporary_stack.
Definition temporary_allocator.hpp:174
~temporary_stack_initializer() noexcept
temporary_stack_initializer(defer_create_t) noexcept
Definition temporary_allocator.hpp:186
temporary_stack_initializer(std::size_t initial_size=default_stack_size)
A wrapper around the memory_stack that is used by the temporary_allocator.
Definition temporary_allocator.hpp:96
growth_tracker get_growth_tracker() noexcept
Definition temporary_allocator.hpp:115
temporary_stack(std::size_t initial_size)
Definition temporary_allocator.hpp:123
growth_tracker set_growth_tracker(growth_tracker t) noexcept
Definition temporary_allocator.hpp:109
detail::temporary_block_allocator::growth_tracker growth_tracker
The type of the handler called when the internal memory_stack grows.
Definition temporary_allocator.hpp:103
std::size_t next_capacity() const noexcept
Definition temporary_allocator.hpp:128
#define WPI_MEMORY_LOG_PREFIX
Definition config.hpp:46
Class wpi::memory::memory_stack and its wpi::memory::allocator_traits specialization.
detail namespace with internal helper functions
Definition input_adapters.h:32
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
Memory namespace.
Definition heap_allocator.hpp:20
Foonathan namespace.
Definition ntcore_cpp.h:26
A memory block.
Definition memory_arena.hpp:28
Definition temporary_allocator.hpp:179
defer_create_t() noexcept
Definition temporary_allocator.hpp:180