1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "chunked_memory_pool_output.h"
- #include "chunked_memory_pool.h"
- #include <library/cpp/yt/memory/ref.h>
- namespace NYT {
- TChunkedMemoryPoolOutput::TChunkedMemoryPoolOutput(TChunkedMemoryPool* pool, size_t chunkSize)
- : Pool_(pool)
- , ChunkSize_(chunkSize)
- { }
- size_t TChunkedMemoryPoolOutput::DoNext(void** ptr)
- {
-
- if (Current_ == End_) {
-
- if (Begin_) {
- Refs_.emplace_back(Begin_, Current_);
- }
-
-
-
- auto spareSize = Pool_->GetCurrentChunkSpareSize();
- auto allocationSize = (spareSize == 0 ? ChunkSize_ : std::min(ChunkSize_, spareSize));
- Begin_ = Pool_->AllocateAligned(allocationSize, 1);
- Current_ = Begin_;
- End_ = Begin_ + allocationSize;
- }
-
-
- *ptr = Current_;
- auto size = End_ - Current_;
- Current_ = End_;
- return size;
- }
- void TChunkedMemoryPoolOutput::DoUndo(size_t size)
- {
-
- Current_ -= size;
- YT_VERIFY(Current_ >= Begin_);
- }
- std::vector<TMutableRef> TChunkedMemoryPoolOutput::Finish()
- {
-
- if (Begin_) {
- Refs_.emplace_back(Begin_, Current_);
- }
-
- if (Current_ < End_) {
- Pool_->Free(Current_, End_);
- }
- return std::move(Refs_);
- }
- }
|