4#ifndef WPI_MEMORY_TRACKING_HPP_INCLUDED
5#define WPI_MEMORY_TRACKING_HPP_INCLUDED
20 template <
class Allocator,
class Tracker>
21 auto set_tracker(
int, Allocator& allocator, Tracker* tracker)
noexcept
22 ->
decltype(allocator.get_allocator().
set_tracker(tracker))
24 return allocator.get_allocator().set_tracker(tracker);
26 template <
class Allocator,
class Tracker>
32 template <
class Tracker,
class BlockAllocator>
36 template <
typename... Args>
38 : BlockAllocator(block_size,
detail::
forward<Args>(args)...), tracker_(nullptr)
44 auto block = BlockAllocator::allocate_block();
46 tracker_->on_allocator_growth(block.memory, block.size);
53 tracker_->on_allocator_shrinking(block.memory, block.size);
54 BlockAllocator::deallocate_block(block);
59 return BlockAllocator::next_block_size();
78 template <
class Tracker,
class BlockOrRawAllocator>
80 : WPI_EBO(Tracker, make_block_allocator_t<BlockOrRawAllocator>)
99 template <
typename... Args>
109 auto block = allocator_type::allocate_block();
110 this->on_allocator_growth(block.memory, block.size);
117 this->on_allocator_shrinking(block.memory, block.size);
118 allocator_type::deallocate_block(block);
124 return allocator_type::next_block_size();
158 template <
class Tracker,
class BlockOrRawAllocator>
169 template <
class Tracker,
class RawAllocator>
171 : WPI_EBO(Tracker, allocator_traits<RawAllocator>::allocator_type)
180 using is_stateful = std::integral_constant<bool, traits::is_stateful::value
181 || !std::is_empty<Tracker>::value>;
229 this->on_node_allocation(mem, size, alignment);
240 this->on_node_allocation(mem, size, alignment);
250 this->on_array_allocation(mem, count, size, alignment);
258 std::size_t alignment)
noexcept
263 this->on_array_allocation(mem, count, size, alignment);
271 this->on_node_deallocation(
ptr, size, alignment);
283 this->on_node_deallocation(
ptr, size, alignment);
290 std::size_t alignment)
noexcept
292 this->on_array_deallocation(
ptr, count, size, alignment);
300 std::size_t alignment)
noexcept
304 this->on_array_deallocation(
ptr, count, size, alignment);
356 template <
class Tracker,
class RawAllocator>
368 template <
typename T,
bool Block>
373 template <
typename T>
378 template <
typename T>
384 template <
class RawAllocator,
class BlockAllocator>
387 template <
template <
typename...>
class RawAllocator,
typename... Args,
388 class OtherBlockAllocator>
392 RawAllocator<typename std::conditional<is_block_or_raw_allocator<Args>::value,
393 OtherBlockAllocator, Args>::type...>;
396 template <
class Tracker,
class RawAllocator>
399 typename RawAllocator::allocator_type>;
401 template <
class Tracker,
class RawAllocator>
410 template <
class Tracker,
class RawAllocator>
418 template <
class RawAllocator,
class Tracker,
typename... Args>
The default specialization of the wpi::memory::allocator_traits.
The default specialization of the allocator_traits for a RawAllocator.
Definition allocator_traits.hpp:292
static void deallocate_array(allocator_type &state, void *array, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:328
traits_detail::allocator_type< Allocator > allocator_type
Definition allocator_traits.hpp:294
static void * allocate_array(allocator_type &state, std::size_t count, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:308
static std::size_t max_array_size(const allocator_type &state)
Definition allocator_traits.hpp:346
static std::size_t max_node_size(const allocator_type &state)
Definition allocator_traits.hpp:338
static std::size_t max_alignment(const allocator_type &state)
Definition allocator_traits.hpp:354
static void * allocate_node(allocator_type &state, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:298
static void deallocate_node(allocator_type &state, void *node, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:318
The default specialization of the composable_allocator_traits for a ComposableAllocator.
Definition allocator_traits.hpp:500
static void * try_allocate_node(allocator_type &state, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:504
static void * try_allocate_array(allocator_type &state, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:513
static bool try_deallocate_node(allocator_type &state, void *node, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:522
static bool try_deallocate_array(allocator_type &state, void *array, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:531
A tracked_allocator that has rebound any BlockAllocator to the corresponding deeply_tracked_block_all...
Definition tracking.hpp:413
auto make_deeply_tracked_allocator(Tracker t, Args &&... args) -> deeply_tracked_allocator< Tracker, RawAllocator >
Definition tracking.hpp:419
Definition tracking.hpp:34
deeply_tracked_block_allocator(std::size_t block_size, Args &&... args)
Definition tracking.hpp:37
void set_tracker(Tracker *tracker) noexcept
Definition tracking.hpp:62
std::size_t next_block_size() const noexcept
Definition tracking.hpp:57
memory_block allocate_block()
Definition tracking.hpp:42
void deallocate_block(memory_block block) noexcept
Definition tracking.hpp:50
A RawAllocator adapter that tracks another allocator using a tracker.
Definition tracking.hpp:172
void deallocate_node(void *ptr, std::size_t size, std::size_t alignment) noexcept
Definition tracking.hpp:269
tracker & get_tracker() noexcept
Definition tracking.hpp:341
bool try_deallocate_node(void *ptr, std::size_t size, std::size_t alignment) noexcept
Definition tracking.hpp:278
void * allocate_array(std::size_t count, std::size_t size, std::size_t alignment)
Definition tracking.hpp:247
void * try_allocate_array(std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition tracking.hpp:257
bool try_deallocate_array(void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition tracking.hpp:299
tracked_allocator(tracker t, allocator_type &&allocator) noexcept
Definition tracking.hpp:192
allocator_type & get_allocator() noexcept
Definition tracking.hpp:328
void * try_allocate_node(std::size_t size, std::size_t alignment) noexcept
Definition tracking.hpp:236
const allocator_type & get_allocator() const noexcept
Definition tracking.hpp:333
~tracked_allocator() noexcept
Definition tracking.hpp:201
const tracker & get_tracker() const noexcept
Definition tracking.hpp:346
void * allocate_node(std::size_t size, std::size_t alignment)
Definition tracking.hpp:226
tracked_allocator(tracker t={}) noexcept
Definition tracking.hpp:187
std::size_t max_node_size() const
Definition tracking.hpp:310
std::size_t max_alignment() const
Definition tracking.hpp:320
tracked_allocator(tracked_allocator &&other) noexcept
Definition tracking.hpp:208
typename allocator_traits< RawAllocator >::allocator_type allocator_type
Definition tracking.hpp:177
auto make_tracked_allocator(Tracker t, RawAllocator &&alloc) -> tracked_allocator< Tracker, typename std::decay< RawAllocator >::type >
Definition tracking.hpp:357
std::size_t max_array_size() const
Definition tracking.hpp:315
Tracker tracker
Definition tracking.hpp:178
std::integral_constant< bool, traits::is_stateful::value||!std::is_empty< Tracker >::value > is_stateful
Definition tracking.hpp:180
tracked_allocator & operator=(tracked_allocator &&other) noexcept
Definition tracking.hpp:214
void deallocate_array(void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition tracking.hpp:289
A BlockAllocator adapter that tracks another allocator using a tracker.
Definition tracking.hpp:81
std::size_t next_block_size() const noexcept
Definition tracking.hpp:122
tracked_block_allocator(std::size_t block_size, tracker t, Args &&... args)
Definition tracking.hpp:100
allocator_type & get_allocator() noexcept
Definition tracking.hpp:129
memory_block allocate_block()
Definition tracking.hpp:107
tracker & get_tracker() noexcept
Definition tracking.hpp:142
make_block_allocator_t< BlockOrRawAllocator > allocator_type
Definition tracking.hpp:83
const tracker & get_tracker() const noexcept
Definition tracking.hpp:147
void deallocate_block(memory_block block) noexcept
Definition tracking.hpp:115
Tracker tracker
Definition tracking.hpp:84
const allocator_type & get_allocator() const noexcept
Definition tracking.hpp:134
tracked_block_allocator(tracker t={}) noexcept
Definition tracking.hpp:89
tracked_block_allocator(tracker t, allocator_type &&alloc) noexcept
Definition tracking.hpp:91
#define WPI_ALIAS_TEMPLATE(Name,...)
Definition config.hpp:73
implementation_defined deeply_tracked_block_allocator
Similar to tracked_block_allocator, but shares the tracker with the higher level allocator.
Definition tracking.hpp:159
implementation_defined make_block_allocator_t
Takes either a BlockAllocator or a RawAllocator.
Definition memory_arena.hpp:622
Class wpi::memory::memory_arena and related functionality regarding BlockAllocators.
detail namespace with internal helper functions
Definition input_adapters.h:32
typename rebind_block_allocator< RawAllocator, deeply_tracked_block_allocator_for< Tracker, RawAllocator > >::type rebound_allocator
Definition tracking.hpp:402
T && forward(typename std::remove_reference< T >::type &t) noexcept
Definition utility.hpp:31
std::remove_reference< T >::type && move(T &&arg) noexcept
Definition utility.hpp:25
auto set_tracker(int, Allocator &allocator, Tracker *tracker) noexcept -> decltype(allocator.get_allocator().set_tracker(tracker))
Definition tracking.hpp:21
memory::deeply_tracked_block_allocator< Tracker, typename RawAllocator::allocator_type > deeply_tracked_block_allocator_for
Definition tracking.hpp:397
Memory namespace.
Definition heap_allocator.hpp:20
Foonathan namespace.
Definition ntcore_cpp.h:26
Definition tracking.hpp:370
Definition tracking.hpp:381
RawAllocator< typename std::conditional< is_block_or_raw_allocator< Args >::value, OtherBlockAllocator, Args >::type... > type
Definition tracking.hpp:391
Definition tracking.hpp:385
Traits that check whether a type models concept RawAllocator.
Definition allocator_traits.hpp:418
A memory block.
Definition memory_arena.hpp:28