4#ifndef WPI_MEMORY_SEGREGATOR_HPP_INCLUDED
5#define WPI_MEMORY_SEGREGATOR_HPP_INCLUDED
22 template <
class RawAllocator>
41 return size <= max_size_;
49 return count * size <= max_size_;
66 std::size_t max_size_;
70 template <
class RawAllocator>
72 std::size_t max_size, RawAllocator&& alloc)
75 typename std::decay<RawAllocator>::type>(max_size,
76 std::forward<RawAllocator>(alloc));
123 template <
class Segregatable,
class RawAllocator>
126 detail::ebo_storage<1, typename allocator_traits<RawAllocator>::allocator_type>)
150 if (get_segregatable().use_allocate_node(size, alignment))
160 if (get_segregatable().use_allocate_node(size, alignment))
170 if (get_segregatable().use_allocate_array(count, size, alignment))
179 std::size_t alignment)
noexcept
181 if (get_segregatable().use_allocate_array(count, size, alignment))
183 count, size, alignment);
215 return get_segregatable().get_allocator();
220 return get_segregatable().get_allocator();
249 template <
class... Segregatables>
252 template <
class Segregatable>
258 template <
class Segregatable,
class RawAllocator>
264 template <
class Segregatable,
class... Tail>
271 template <
class Segregator,
class Fallback = null_allocator>
274 typename std::decay<Fallback>::type>
277 typename std::decay<Segregator>::type,
278 typename std::decay<Fallback>::type>(std::forward<Segregator>(seg),
279 std::forward<Fallback>(f));
282 template <
class Segregator,
typename... Rest>
289 rest)...))>(std::forward<Segregator>(seg),
291 std::forward<Rest>(rest)...));
294 template <std::
size_t I,
class Segregator>
297 template <
class Segregator,
class Fallback>
300 using type =
typename Segregator::allocator_type;
313 template <std::
size_t I,
class Segregator,
class Fallback>
317 using type =
typename base::type;
330 template <
class Fallback>
335 static const std::size_t size = 0u;
348 template <
class Segregator,
class Fallback>
354 static const std::size_t size = base::size + 1u;
379 template <
class... Allocators>
385 template <
typename... Args>
393 template <
class Segregator>
401 template <std::
size_t I,
class Segregator>
407 template <std::
size_t I,
class Segregator,
class Fallback>
414 template <std::
size_t I,
class Segregator,
class Fallback>
416 ->
const segregatable_allocator_type<I, binary_segregator<Segregator, Fallback>>
424 template <
class Segregator>
430 template <
class Segregator,
class Fallback>
437 template <
class Segregator,
class Fallback>
439 ->
const fallback_allocator_type<binary_segregator<Segregator, Fallback>>&
The default specialization of the wpi::memory::allocator_traits.
This class is a wrapper around std::array that does compile time size checking.
Definition array.h:26
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
A RawAllocator that either uses the Segregatable or the other RawAllocator.
Definition segregator.hpp:127
std::size_t max_array_size() const
Definition segregator.hpp:199
void deallocate_node(void *ptr, std::size_t size, std::size_t alignment) noexcept
Definition segregator.hpp:158
typename allocator_traits< RawAllocator >::allocator_type fallback_allocator_type
Definition segregator.hpp:134
void deallocate_array(void *array, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition segregator.hpp:178
typename segregatable::allocator_type segregatable_allocator_type
Definition segregator.hpp:133
segregatable_allocator_type & get_segregatable_allocator() noexcept
Definition segregator.hpp:213
std::size_t max_node_size() const
Definition segregator.hpp:194
void * allocate_node(std::size_t size, std::size_t alignment)
Definition segregator.hpp:148
fallback_allocator_type & get_fallback_allocator() noexcept
Definition segregator.hpp:227
std::size_t max_alignemnt() const
Definition segregator.hpp:204
const segregatable_allocator_type & get_segregatable_allocator() const noexcept
Definition segregator.hpp:218
const fallback_allocator_type & get_fallback_allocator() const noexcept
Definition segregator.hpp:232
void * allocate_array(std::size_t count, std::size_t size, std::size_t alignment)
Definition segregator.hpp:168
Segregatable segregatable
Definition segregator.hpp:132
binary_segregator(segregatable s, fallback_allocator_type fallback=fallback_allocator_type())
Definition segregator.hpp:138
T & get() noexcept
Definition ebo_storage.hpp:27
A composable RawAllocator that will always fail.
Definition segregator.hpp:83
void * allocate_node(std::size_t size, std::size_t)
Definition segregator.hpp:87
void deallocate_node(void *, std::size_t, std::size_t) noexcept
Definition segregator.hpp:93
void * try_allocate_node(std::size_t, std::size_t) noexcept
Definition segregator.hpp:100
bool try_deallocate_node(void *, std::size_t, std::size_t) noexcept
Definition segregator.hpp:107
A special case of out_of_memory errors thrown when a low-level allocator with a fixed size runs out o...
Definition error.hpp:121
Creates multiple nested binary_segregator.
Definition segregator.hpp:381
auto make_segregator(Args &&... args) -> segregator< typename std::decay< Args >::type... >
Definition segregator.hpp:386
typename detail::fallback_type< Segregator >::type fallback_allocator_type
The type of the final fallback RawAllocator.
Definition segregator.hpp:425
typename detail::segregatable_type< I, Segregator >::type segregatable_allocator_type
The type of the Ith Segregatable.
Definition segregator.hpp:402
A Segregatable that allocates until a maximum size.
Definition segregator.hpp:24
allocator_type & get_allocator() noexcept
Definition segregator.hpp:54
const allocator_type & get_allocator() const noexcept
Definition segregator.hpp:59
threshold_segregatable(std::size_t max_size, allocator_type alloc=allocator_type())
Definition segregator.hpp:30
bool use_allocate_array(std::size_t count, std::size_t size, std::size_t) noexcept
Definition segregator.hpp:47
typename allocator_traits< RawAllocator >::allocator_type allocator_type
Definition segregator.hpp:26
bool use_allocate_node(std::size_t size, std::size_t) noexcept
Definition segregator.hpp:39
#define WPI_MEMORY_LOG_PREFIX
Definition config.hpp:46
#define WPI_ALIAS_TEMPLATE(Name,...)
Definition config.hpp:73
detail namespace with internal helper functions
Definition input_adapters.h:32
auto make_segregator(Segregator &&seg, Fallback &&f=null_allocator{}) -> binary_segregator< typename std::decay< Segregator >::type, typename std::decay< Fallback >::type >
Definition segregator.hpp:272
Memory namespace.
Definition heap_allocator.hpp:20
threshold_segregatable< typename std::decay< RawAllocator >::type > threshold(std::size_t max_size, RawAllocator &&alloc)
Definition segregator.hpp:71
auto get_fallback_allocator(const binary_segregator< Segregator, Fallback > &s) -> const fallback_allocator_type< binary_segregator< Segregator, Fallback > > &
Definition segregator.hpp:438
auto get_segregatable_allocator(const binary_segregator< Segregator, Fallback > &s) -> const segregatable_allocator_type< I, binary_segregator< Segregator, Fallback > >
Definition segregator.hpp:415
Foonathan namespace.
Definition ntcore_cpp.h:26
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition PointerIntPair.h:270
Contains information about an allocator.
Definition error.hpp:23
typename base::type type
Definition segregator.hpp:352
static const type & get(const binary_segregator< Segregator, Fallback > &s)
Definition segregator.hpp:361
static type & get(binary_segregator< Segregator, Fallback > &s)
Definition segregator.hpp:356
Definition segregator.hpp:332
static const type & get(const Fallback &f)
Definition segregator.hpp:342
static type & get(Fallback &f)
Definition segregator.hpp:337
Fallback type
Definition segregator.hpp:333
Definition segregator.hpp:250
static const type & get(const binary_segregator< Segregator, Fallback > &s)
Definition segregator.hpp:307
static type & get(binary_segregator< Segregator, Fallback > &s)
Definition segregator.hpp:302
typename Segregator::allocator_type type
Definition segregator.hpp:300
static type & get(binary_segregator< Segregator, Fallback > &s)
Definition segregator.hpp:319
static const type & get(const binary_segregator< Segregator, Fallback > &s)
Definition segregator.hpp:324
typename base::type type
Definition segregator.hpp:317
Definition segregator.hpp:295
The number of Segregatable a segregator has.
Definition segregator.hpp:395
static const std::size_t value
Definition segregator.hpp:396
#define WPI_MEMORY_UNREACHABLE(Msg)
Definition assert.hpp:48