MCPcopy Create free account
hub / github.com/bytedance/bolt / newRange

Method newRange

bolt/common/memory/StreamArena.cpp:37–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35StreamArena::StreamArena(memory::MemoryPool* pool) : pool_(pool) {}
36
37void StreamArena::newRange(
38 int32_t bytes,
39 ByteRange* /*lastRange*/,
40 ByteRange* range) {
41 BOLT_CHECK_GT(bytes, 0, "StreamArena::newRange can't be zero length");
42 const memory::MachinePageCount numPages =
43 memory::AllocationTraits::numPages(bytes);
44 // If new range 'bytes' is larger than the largest class page size, then we
45 // allocate a large chunk of contiguous memory for this range.
46 if (numPages > pool_->largestSizeClass()) {
47 memory::ContiguousAllocation largeAllocation;
48 pool_->allocateContiguous(numPages, largeAllocation);
49 range->buffer = largeAllocation.data();
50 range->size = largeAllocation.size();
51 range->position = 0;
52 size_ += range->size;
53 largeAllocations_.push_back(std::move(largeAllocation));
54 return;
55 }
56
57 const int32_t numRuns = allocation_.numRuns();
58 if (currentRun_ >= numRuns) {
59 if (numRuns > 0) {
60 allocations_.push_back(
61 std::make_unique<memory::Allocation>(std::move(allocation_)));
62 }
63 pool_->allocateNonContiguous(
64 std::max(allocationQuantum_, numPages), allocation_);
65 currentRun_ = 0;
66 currentOffset_ = 0;
67 size_ += allocation_.byteSize();
68 }
69 auto run = allocation_.runAt(currentRun_);
70 range->buffer = run.data() + currentOffset_;
71 const int32_t availableBytes = run.numBytes() - currentOffset_;
72 range->size = std::min(bytes, availableBytes);
73 range->position = 0;
74 currentOffset_ += range->size;
75 BOLT_DCHECK_LE(currentOffset_, run.numBytes());
76 if (currentOffset_ == run.numBytes()) {
77 ++currentRun_;
78 ++currentOffset_ = 0;
79 }
80}
81
82void StreamArena::newTinyRange(
83 int32_t bytes,

Callers 2

extendMethod · 0.45
TEST_FFunction · 0.45

Calls 12

numRunsMethod · 0.80
runAtMethod · 0.80
numBytesMethod · 0.80
maxFunction · 0.50
minFunction · 0.50
largestSizeClassMethod · 0.45
allocateContiguousMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
allocateNonContiguousMethod · 0.45
byteSizeMethod · 0.45

Tested by 2

extendMethod · 0.36
TEST_FFunction · 0.36