12 #include "allocator_base.hpp"
13 #include "internal/reallocator.hpp"
17 inline namespace v_100 {
35 template <
class Allocator,
unsigned MinSize,
unsigned MaxSize,
unsigned StepSize>
38 static constexpr
bool supports_truncated_deallocation =
false;
39 static constexpr
unsigned alignment = Allocator::alignment;
41 static_assert(MinSize < MaxSize,
"MinSize must be smaller than MaxSize");
42 static_assert((MaxSize - MinSize + 1) % StepSize == 0,
"Incorrect ranges or step size!");
44 static constexpr
unsigned number_of_buckets = ((MaxSize - MinSize + 1) / StepSize);
45 static constexpr
unsigned max_size = MaxSize;
46 static constexpr
unsigned min_size = MinSize;
47 static constexpr
unsigned step_size = StepSize;
49 using allocator = Allocator;
51 Allocator _buckets[number_of_buckets];
55 for (
size_t i = 0; i < number_of_buckets; i++) {
56 _buckets[i].set_min_max(MinSize + i * StepSize, MinSize + (i + 1) * StepSize - 1);
60 static constexpr
size_t good_size(
size_t n) noexcept {
61 return (number_of_buckets - (max_size - n)/step_size + 1) * step_size;
73 while (i < number_of_buckets) {
74 if (_buckets[i].min_size() <= n && n <= _buckets[i].max_size()) {
75 return _buckets[i].allocate(n);
89 return b && (MinSize <= b.length && b.length <= MaxSize);
104 if (n != 0 && (n < MinSize || n > MaxSize)) {
108 if (internal::is_reallocation_handled_default(*
this, b, n)) {
115 auto currentAllocator = find_matching_allocator(b.length);
116 auto newAllocator = find_matching_allocator(alignedLength);
118 if (currentAllocator == newAllocator) {
135 assert(!
"It is not wise to let me deallocate a foreign Block!");
139 auto currentAllocator = find_matching_allocator(b.length);
140 currentAllocator->deallocate(b);
147 template <
typename U = Allocator>
148 typename std::enable_if<traits::has_deallocate_all<U>::value,
void>::type
151 for (
auto &item : _buckets) {
157 Allocator *find_matching_allocator(
size_t n) noexcept
159 assert(MinSize <= n && n <= MaxSize);
161 return &_buckets[(v - MinSize) / StepSize];
165 template <
class Allocator,
unsigned MinSize,
unsigned MaxSize,
unsigned StepSize>
166 const unsigned bucketizer<Allocator, MinSize, MaxSize, StepSize>::number_of_buckets;
168 using namespace v_100;
block allocate(size_t n) noexcept
bool reallocate_with_copy(OldAllocator &oldAllocator, NewAllocator &newAllocator, block &b, size_t n) noexcept
constexpr size_t round_to_alignment(size_t basis, size_t n) noexcept
std::enable_if< traits::has_deallocate_all< U >::value, void >::type deallocate_all() noexcept
bool reallocate(block &b, size_t n) noexcept
bool owns(const block &b) const noexcept
void deallocate(block &b) noexcept