* @brief Resizes the queue to a new capacity, preserving the most recent elements. */
| 266 | * @brief Resizes the queue to a new capacity, preserving the most recent elements. |
| 267 | */ |
| 268 | void resize(std::size_t newCapacity) |
| 269 | { |
| 270 | if (newCapacity < 1) |
| 271 | newCapacity = 1; |
| 272 | |
| 273 | if (newCapacity == m_capacity) |
| 274 | return; |
| 275 | |
| 276 | const std::size_t newStorage = roundUpToPowerOfTwo(newCapacity); |
| 277 | std::shared_ptr<T[]> newData = makeStorage(newStorage); |
| 278 | std::size_t elementsToCopy = std::min(m_size, newCapacity); |
| 279 | for (std::size_t i = 0; i < elementsToCopy; ++i) |
| 280 | newData[i] = std::move((*this)[m_size - elementsToCopy + i]); |
| 281 | |
| 282 | m_start = 0; |
| 283 | m_size = elementsToCopy; |
| 284 | m_capacity = newCapacity; |
| 285 | m_storageCapacity = newStorage; |
| 286 | m_storageMask = newStorage - 1; |
| 287 | m_data = std::move(newData); |
| 288 | } |
| 289 | |
| 290 | private: |
| 291 | // Plot-scale buffers are written per frame; smaller ones would waste page-locked quota |