66 my_oracle(std::move(oracle)),
67 my_total(my_oracle->total()),
68 my_max_slabs(sanisizer::cast<decltype(my_max_slabs)>(max_slabs))
70 my_all_slabs.reserve(max_slabs);
71 my_current_cache.reserve(max_slabs);
72 my_future_cache.reserve(max_slabs);
146 std::pair<const Slab_*, Index_>
next(Ifunction_ identify, Cfunction_ create, Pfunction_ populate) {
147 Index_ index = this->
next();
148 auto slab_info = identify(index);
149 if (slab_info.first == my_last_slab_id && my_last_slab) {
150 return std::make_pair(my_last_slab, slab_info.second);
152 my_last_slab_id = slab_info.first;
155 if (my_counter - 1 == my_refresh_point) {
159 my_future_cache[slab_info.first] = NULL;
160 my_in_need.push_back(slab_info.first);
161 decltype(my_max_slabs) used_slabs = 1;
162 auto last_future_slab_id = slab_info.first;
164 while (++my_refresh_point < my_total) {
165 auto future_index = my_oracle->get(my_refresh_point);
166 auto future_slab_info = identify(future_index);
167 if (last_future_slab_id == future_slab_info.first) {
171 last_future_slab_id = future_slab_info.first;
172 if (my_future_cache.find(future_slab_info.first) != my_future_cache.end()) {
176 if (used_slabs == my_max_slabs) {
181 auto ccIt = my_current_cache.find(future_slab_info.first);
182 if (ccIt == my_current_cache.end()) {
183 my_future_cache[future_slab_info.first] = NULL;
184 my_in_need.push_back(future_slab_info.first);
187 auto slab_ptr = ccIt->second;
188 my_future_cache[future_slab_info.first] = slab_ptr;
189 my_current_cache.erase(ccIt);
190 if constexpr(track_reuse_) {
191 my_to_reuse.emplace_back(future_slab_info.first, slab_ptr);
196 auto cIt = my_current_cache.begin();
197 for (
auto a : my_in_need) {
198 if (cIt != my_current_cache.end()) {
199 my_to_populate.emplace_back(a, cIt->second);
200 my_future_cache[a] = cIt->second;
205 my_all_slabs.push_back(create());
206 auto slab_ptr = &(my_all_slabs.back());
207 my_to_populate.emplace_back(a, slab_ptr);
208 my_future_cache[a] = slab_ptr;
213 if constexpr(track_reuse_) {
214 populate(my_to_populate, my_to_reuse);
216 populate(my_to_populate);
219 my_to_populate.clear();
220 if constexpr(track_reuse_) {
232 my_current_cache.clear();
233 my_current_cache.swap(my_future_cache);
237 auto ccIt = my_current_cache.find(slab_info.first);
238 my_last_slab = ccIt->second;
239 return std::make_pair(my_last_slab, slab_info.second);