Return the next aligned memory address
| 191 | |
| 192 | // Return the next aligned memory address |
| 193 | void* 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. |
| 215 | void HeapAllocator::release(void* pointer, size_t size) { |
nothing calls this directly
no outgoing calls
no test coverage detected