| 14 | { } |
| 15 | |
| 16 | size_t TChunkedMemoryPoolOutput::DoNext(void** ptr) |
| 17 | { |
| 18 | // Check if the current chunk is exhausted. |
| 19 | if (Current_ == End_) { |
| 20 | // Emplace the (whole) last chunk, if any. |
| 21 | if (Begin_) { |
| 22 | Refs_.emplace_back(Begin_, Current_); |
| 23 | } |
| 24 | // Allocate a new chunk. |
| 25 | // Use |AllocateAligned| to get a chance to free some memory afterwards. |
| 26 | // Tune the number of bytes requested from the pool to try avoid allocations. |
| 27 | auto spareSize = Pool_->GetCurrentChunkSpareSize(); |
| 28 | auto allocationSize = (spareSize == 0 ? ChunkSize_ : std::min(ChunkSize_, spareSize)); |
| 29 | Begin_ = Pool_->AllocateAligned(allocationSize, /* align */ 1); |
| 30 | Current_ = Begin_; |
| 31 | End_ = Begin_ + allocationSize; |
| 32 | } |
| 33 | |
| 34 | // Return the unused part of the current chunk. |
| 35 | // This could be the whole chunk allocated above. |
| 36 | *ptr = Current_; |
| 37 | auto size = End_ - Current_; |
| 38 | Current_ = End_; |
| 39 | return size; |
| 40 | } |
| 41 | |
| 42 | void TChunkedMemoryPoolOutput::DoUndo(size_t size) |
| 43 | { |
nothing calls this directly
no test coverage detected