MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / mergeUnits

Method mergeUnits

src/memory/HeapAllocator.cpp:298–319  ·  view source on GitHub ↗

Merge two contiguous memory units that are not allocated. Memory unit 2 will be merged into memory unit 1 and memory unit 2 will be removed

Source from the content-addressed store, hash-verified

296// Merge two contiguous memory units that are not allocated.
297/// Memory unit 2 will be merged into memory unit 1 and memory unit 2 will be removed
298void HeapAllocator::mergeUnits(MemoryUnitHeader* unit1, MemoryUnitHeader* unit2) {
299
300 assert(unit2->previousUnit == unit1);
301 assert(unit1->nextUnit == unit2);
302 assert(!unit1->isAllocated);
303 assert(!unit2->isAllocated);
304 assert(unit1->isNextContiguousMemory);
305
306 unit1->size += unit2->size + sizeof(MemoryUnitHeader);
307 unit1->nextUnit = unit2->nextUnit;
308 assert(unit1->nextUnit != unit1);
309 if (unit2->nextUnit != nullptr) {
310 unit2->nextUnit->previousUnit = unit1;
311 }
312 unit1->isNextContiguousMemory = unit2->isNextContiguousMemory;
313
314 // Destroy unit 2
315 unit2->~MemoryUnitHeader();
316
317 assert(unit1->previousUnit == nullptr || unit1->previousUnit->nextUnit == unit1);
318 assert(unit1->nextUnit == nullptr || unit1->nextUnit->previousUnit == unit1);
319}
320
321// Reserve more memory for the allocator
322void HeapAllocator::reserve(size_t sizeToAllocate) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected