Get the 'num_buffers' buffers with the highest memory address from the list to free. The average time complexity is n log n, where n is the current size of the list.
| 77 | /// free. The average time complexity is n log n, where n is the current size of the |
| 78 | /// list. |
| 79 | vector<BufferHandle> GetBuffersToFree(int64_t num_buffers) { |
| 80 | vector<BufferHandle> buffers; |
| 81 | DCHECK_LE(num_buffers, free_list_.size()); |
| 82 | // Sort the list so we can free the buffers with higher memory addresses. |
| 83 | // Note that the sorted list is still a valid min-heap. |
| 84 | std::sort(free_list_.begin(), free_list_.end(), SortCompare); |
| 85 | |
| 86 | for (int64_t i = 0; i < num_buffers; ++i) { |
| 87 | buffers.emplace_back(std::move(free_list_.back())); |
| 88 | free_list_.pop_back(); |
| 89 | } |
| 90 | return buffers; |
| 91 | } |
| 92 | |
| 93 | /// Returns the number of buffers currently in the list. |
| 94 | int64_t Size() const { return free_list_.size(); } |