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

Method computeAlignedAddress

src/memory/HeapAllocator.cpp:193–212  ·  view source on GitHub ↗

Return the next aligned memory address

Source from the content-addressed store, hash-verified

191
192// Return the next aligned memory address
193void* HeapAllocator::computeAlignedAddress(void* unalignedAddress) {
194
195 // Take care of alignment to make sure that we always return an address to the
196 // enforce the global alignment of the library
197
198 // Compute the aligned address
199 ptrdiff_t alignmentOffset;
200 void* alignedPointer = alignAddress(unalignedAddress, GLOBAL_ALIGNMENT, alignmentOffset);
201
202 uintptr_t alignedAddress = reinterpret_cast<uintptr_t>(alignedPointer);
203
204 // Store the adjustment in the byte immediately preceding the adjusted address.
205 // This way we can find again the original allocated memory address returned by malloc
206 // when this memory unit is released.
207 assert(alignmentOffset <= GLOBAL_ALIGNMENT);
208 uint8* pAlignedMemory = reinterpret_cast<uint8*>(alignedAddress);
209 pAlignedMemory[-1] = static_cast<uint8>(alignmentOffset);
210
211 return alignedPointer;
212}
213
214// Release previously allocated memory.
215void HeapAllocator::release(void* pointer, size_t size) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected