157 std::pair<const Slab_*, Index_>
next(Ifunction_ identify, Ufunction_ upper_size, Afunction_ actual_size, Cfunction_ create, Pfunction_ populate) {
158 Index_ index = this->
next();
159 auto slab_info = identify(index);
160 if (slab_info.first == my_last_slab_id && my_last_slab_num !=
static_cast<size_t>(-1)) {
161 return std::make_pair(my_all_slabs.data() + my_last_slab_num, slab_info.second);
163 my_last_slab_id = slab_info.first;
166 if (my_counter - 1 == my_refresh_point) {
170 my_used_size = upper_size(slab_info.first);
171 requisition_new_slab(slab_info.first);
173 auto last_future_slab_id = slab_info.first;
174 while (++my_refresh_point < my_total) {
175 auto future_index = my_oracle->get(my_refresh_point);
176 auto future_slab_info = identify(future_index);
177 if (last_future_slab_id == future_slab_info.first) {
181 last_future_slab_id = future_slab_info.first;
182 if (my_future_cache.find(future_slab_info.first) != my_future_cache.end()) {
186 auto ccIt = my_current_cache.find(future_slab_info.first);
187 if (ccIt != my_current_cache.end()) {
188 size_t slab_num = ccIt->second;
189 auto candidate = my_used_size + actual_size(future_slab_info.first, my_all_slabs[slab_num]);
190 if (candidate > my_max_size) {
193 my_used_size = candidate;
194 my_future_cache[future_slab_info.first] = slab_num;
195 my_to_reuse.emplace_back(future_slab_info.first, slab_num);
196 my_current_cache.erase(ccIt);
198 auto candidate = my_used_size + upper_size(future_slab_info.first);
199 if (candidate > my_max_size) {
202 my_used_size = candidate;
203 requisition_new_slab(future_slab_info.first);
207 auto cIt = my_current_cache.begin();
208 for (
auto a : my_in_need) {
209 if (cIt != my_current_cache.end()) {
210 size_t slab_num = cIt->second;
211 my_to_populate.emplace_back(a, slab_num);
212 my_future_cache[a] = slab_num;
215 size_t slab_num = my_all_slabs.size();
216 my_all_slabs.push_back(create());
217 my_to_populate.emplace_back(a, slab_num);
218 my_future_cache[a] = slab_num;
223 for (; cIt != my_current_cache.end(); ++cIt) {
224 my_free_pool.emplace_back(cIt->second);
227 populate(my_to_populate, my_to_reuse, my_all_slabs);
228 my_to_populate.clear();
231 my_current_cache.clear();
232 my_current_cache.swap(my_future_cache);
236 auto ccIt = my_current_cache.find(slab_info.first);
237 my_last_slab_num = ccIt->second;
238 return std::make_pair(my_all_slabs.data() + my_last_slab_num, slab_info.second);