67 my_oracle(std::move(oracle)),
68 my_total(my_oracle->total()),
69 my_max_slabs(sanisizer::cast<I<decltype(my_max_slabs)> >(max_slabs))
71 my_all_slabs.reserve(max_slabs);
72 my_current_cache.reserve(max_slabs);
73 my_future_cache.reserve(max_slabs);
147 std::pair<const Slab_*, Index_>
next(Ifunction_ identify, Cfunction_ create, Pfunction_ populate) {
148 Index_ index = this->
next();
149 auto slab_info = identify(index);
150 if (slab_info.first == my_last_slab_id && my_last_slab) {
151 return std::make_pair(my_last_slab, slab_info.second);
153 my_last_slab_id = slab_info.first;
156 if (my_counter - 1 == my_refresh_point) {
160 my_future_cache[slab_info.first] = NULL;
161 my_in_need.push_back(slab_info.first);
162 I<
decltype(my_max_slabs)> used_slabs = 1;
163 auto last_future_slab_id = slab_info.first;
165 while (++my_refresh_point < my_total) {
166 auto future_index = my_oracle->get(my_refresh_point);
167 auto future_slab_info = identify(future_index);
168 if (last_future_slab_id == future_slab_info.first) {
172 last_future_slab_id = future_slab_info.first;
173 if (my_future_cache.find(future_slab_info.first) != my_future_cache.end()) {
177 if (used_slabs == my_max_slabs) {
182 auto ccIt = my_current_cache.find(future_slab_info.first);
183 if (ccIt == my_current_cache.end()) {
184 my_future_cache[future_slab_info.first] = NULL;
185 my_in_need.push_back(future_slab_info.first);
188 auto slab_ptr = ccIt->second;
189 my_future_cache[future_slab_info.first] = slab_ptr;
190 my_current_cache.erase(ccIt);
191 if constexpr(track_reuse_) {
192 my_to_reuse.emplace_back(future_slab_info.first, slab_ptr);
197 auto cIt = my_current_cache.begin();
198 for (
auto a : my_in_need) {
199 if (cIt != my_current_cache.end()) {
200 my_to_populate.emplace_back(a, cIt->second);
201 my_future_cache[a] = cIt->second;
206 my_all_slabs.push_back(create());
207 auto slab_ptr = &(my_all_slabs.back());
208 my_to_populate.emplace_back(a, slab_ptr);
209 my_future_cache[a] = slab_ptr;
214 if constexpr(track_reuse_) {
215 populate(my_to_populate, my_to_reuse);
217 populate(my_to_populate);
220 my_to_populate.clear();
221 if constexpr(track_reuse_) {
233 my_current_cache.clear();
234 my_current_cache.swap(my_future_cache);
238 auto ccIt = my_current_cache.find(slab_info.first);
239 my_last_slab = ccIt->second;
240 return std::make_pair(my_last_slab, slab_info.second);