An allocator which owns multiple instances of a given sub allocator. When allocating it will attempt to use the first available allocator. Upon failure it will instead create a new instance and allocate from it.
More...
|
| | cascading () noexcept |
| |
| | cascading (const cascading &)=delete |
| |
| | cascading (cascading &&other) noexcept(std::is_nothrow_move_constructible_v< node >) |
| |
| | ~cascading () |
| |
| cascading & | operator= (const cascading &)=delete |
| |
| cascading & | operator= (cascading &&rhs) noexcept(std::is_nothrow_move_assignable_v< node >) |
| |
| bool | operator== (const cascading &rhs) const noexcept |
| |
| bool | operator!= (const cascading &rhs) const noexcept |
| |
| void * | allocate (size_type n) noexcept(std::is_nothrow_default_constructible_v< node > &&detail::has_nothrow_allocate_v< Alloc > &&(!detail::has_max_size_v< Alloc >||detail::has_nothrow_max_size_v< Alloc >)) |
| | Attempts to allocate a chunk of memory defined by n. More...
|
| |
| void | deallocate (void *p, size_type n) noexcept(std::is_nothrow_destructible_v< node > &&detail::has_nothrow_owns_v< Alloc > &&detail::has_nothrow_deallocate_v< Alloc >) |
| | Attempts to deallocate the memory at location p. More...
|
| |
| template<typename T , typename... Args> |
| std::enable_if< detail::has_construct_v< Alloc, T *, Args... >, void >::type | construct (T *p, Args &&... args) noexcept(detail::has_nothrow_owns_v< Alloc > &&detail::has_nothrow_construct_v< Alloc, T *, Args... >) |
| | Constructs an object of T with the given ...args at the given location. More...
|
| |
| template<typename T > |
| std::enable_if< detail::has_destroy_v< Alloc, T * >, void >::type | destroy (T *p) noexcept(detail::has_nothrow_owns_v< Alloc > &&detail::has_nothrow_destroy_v< Alloc, T * >) |
| | Destructs an object of T at the given location. More...
|
| |
| template<typename A = Alloc> |
| std::enable_if< detail::has_max_size_v< A >, size_type >::type | max_size () const noexcept(detail::has_nothrow_max_size_v< A >) |
| | Returns the maximum size that an allocation can be. More...
|
| |
| bool | owns (void *p) const noexcept(detail::has_nothrow_owns_v< Alloc >) |
| | Returns whether or not the allocator owns the given location in memory. More...
|
| |
template<typename Alloc>
class ktl::cascading< Alloc >
An allocator which owns multiple instances of a given sub allocator. When allocating it will attempt to use the first available allocator. Upon failure it will instead create a new instance and allocate from it.
- Note
- Deallocation can take O(n) time as it may have to traverse multiple allocator instances to find the right one. The allocator type must be default-constructible, which means any variation of stack_allocator can't be used. The allocator type must also have an owns(*ptr) method, which means any variation of mallocator can't be used.
- Template Parameters
-
| Alloc | The allocator type to create instances from |
| Atomic | The atomic type to use for reference counting. Threading is not implemented, so this defaults to ktl::notomic<size_t> |