inlinevoid LinearAlloc::SetFirstObject(void* begin, size_t bytes) const {
DCHECK(track_allocations_); if (ArenaAllocator::IsRunningOnMemoryTool()) {
bytes += ArenaAllocator::kMemoryToolRedZoneBytes;
}
uint8_t* end = static_cast<uint8_t*>(begin) + bytes;
Arena* arena = allocator_.GetHeadArena();
DCHECK_NE(arena, nullptr); // The object would either be in the head arena or the next one. if (UNLIKELY(begin < arena->Begin() || begin >= arena->End())) {
arena = arena->Next();
}
DCHECK(begin >= arena->Begin() && end <= arena->End());
down_cast<TrackedArena*>(arena)->SetFirstObject(static_cast<uint8_t*>(begin), end);
}
if (allocator_.CurrentArenaUnusedBytes() < required_size + mem_tool_bytes) { // The allocator will require a new arena, which is expected to be // 16-byte aligned.
static_assert(ArenaAllocator::kArenaAlignment >= 16, "Expecting sufficient alignment for new Arena.");
required_size = size + RoundUp(sizeof(TrackingHeader), 16);
} // Using ArenaAllocator's AllocAlign16 now would disturb the alignment by // trying to make header 16-byte aligned. The alignment requirements are // already addressed here. Now we want allocator to just bump the pointer.
ptr = static_cast<uint8_t*>(allocator_.Alloc(required_size)); new (ptr) TrackingHeader(required_size, kind, /*is_16_aligned=*/true);
SetFirstObject(ptr, required_size); return AlignUp(ptr + sizeof(TrackingHeader), 16);
} else { return allocator_.AllocAlign16(size);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.