68 my_oracle(std::move(oracle)),
69 my_total(my_oracle->total()),
70 my_max_slabs(sanisizer::cast<I<decltype(my_max_slabs)> >(max_slabs))
72 my_all_slabs.reserve(max_slabs);
73 my_current_cache.reserve(max_slabs);
74 my_future_cache.reserve(max_slabs);
148 std::pair<const Slab_*, Index_>
next(Ifunction_ identify, Cfunction_ create, Pfunction_ populate) {
149 Index_ index = this->
next();
150 auto slab_info = identify(index);
151 if (slab_info.first == my_last_slab_id && my_last_slab) {
152 return std::make_pair(my_last_slab, slab_info.second);
154 my_last_slab_id = slab_info.first;
157 if (my_counter - 1 == my_refresh_point) {
161 my_future_cache[slab_info.first] = NULL;
162 my_in_need.push_back(slab_info.first);
163 I<
decltype(my_max_slabs)> used_slabs = 1;
164 auto last_future_slab_id = slab_info.first;
166 while (++my_refresh_point < my_total) {
167 auto future_index = my_oracle->get(my_refresh_point);
168 auto future_slab_info = identify(future_index);
169 if (last_future_slab_id == future_slab_info.first) {
173 last_future_slab_id = future_slab_info.first;
174 if (my_future_cache.find(future_slab_info.first) != my_future_cache.end()) {
178 if (used_slabs == my_max_slabs) {
183 auto ccIt = my_current_cache.find(future_slab_info.first);
184 if (ccIt == my_current_cache.end()) {
185 my_future_cache[future_slab_info.first] = NULL;
186 my_in_need.push_back(future_slab_info.first);
189 auto slab_ptr = ccIt->second;
190 my_future_cache[future_slab_info.first] = slab_ptr;
191 my_current_cache.erase(ccIt);
192 if constexpr(track_reuse_) {
193 my_to_reuse.emplace_back(future_slab_info.first, slab_ptr);
198 auto cIt = my_current_cache.begin();
199 for (
auto a : my_in_need) {
200 if (cIt != my_current_cache.end()) {
201 my_to_populate.emplace_back(a, cIt->second);
202 my_future_cache[a] = cIt->second;
207 my_all_slabs.push_back(create());
208 auto slab_ptr = &(my_all_slabs.back());
209 my_to_populate.emplace_back(a, slab_ptr);
210 my_future_cache[a] = slab_ptr;
215 if constexpr(track_reuse_) {
216 populate(my_to_populate, my_to_reuse);
218 populate(my_to_populate);
221 my_to_populate.clear();
222 if constexpr(track_reuse_) {
234 my_current_cache.clear();
235 my_current_cache.swap(my_future_cache);
239 auto ccIt = my_current_cache.find(slab_info.first);
240 my_last_slab = ccIt->second;
241 return std::make_pair(my_last_slab, slab_info.second);