Skip to content

Commit

Permalink
DefaultRawMemoryAllocator: fixed alignment in AllocateAligned
Browse files Browse the repository at this point in the history
The alignment must be a power of two and a multiple of sizeof(void*))
  • Loading branch information
TheMostDiligent committed Nov 4, 2024
1 parent 5196c52 commit dbfcb85
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Common/src/DefaultRawMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ void DefaultRawMemoryAllocator::Free(void* Ptr)
void* DefaultRawMemoryAllocator::AllocateAligned(size_t Size, size_t Alignment, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
{
VERIFY_EXPR(Size > 0 && Alignment > 0);
// Alignment must be a power of two and a multiple of sizeof(void*))
Alignment = std::max(Alignment, sizeof(void*));
// Size must be an integral multiple of alignment,
// or aligned_alloc will return null
Size = AlignUp(Size, Alignment);
return ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber);
}
Expand Down

0 comments on commit dbfcb85

Please sign in to comment.