From 39d2dab74eb57b312ac2a88f465a3d28226f9785 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 20 Oct 2024 09:40:41 -0700 Subject: [PATCH] DefaultRawMemoryAllocator: refactoring to reduce the number of #if conditions --- Common/src/DefaultRawMemoryAllocator.cpp | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Common/src/DefaultRawMemoryAllocator.cpp b/Common/src/DefaultRawMemoryAllocator.cpp index 84b62ac46..6b9a5fdd2 100644 --- a/Common/src/DefaultRawMemoryAllocator.cpp +++ b/Common/src/DefaultRawMemoryAllocator.cpp @@ -58,26 +58,34 @@ void DefaultRawMemoryAllocator::Free(void* Ptr) free(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); - Size = AlignUp(Size, Alignment); +#ifdef ALIGNED_MALLOC +# undef ALIGNED_MALLOC +#endif +#ifdef ALIGNED_FREE +# undef ALIGNED_FREE +#endif + #ifdef USE_CRT_MALLOC_DBG - return _aligned_malloc_dbg(Size, Alignment, dbgFileName, dbgLineNumber); +# define ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber) _aligned_malloc_dbg(Size, Alignment, dbgFileName, dbgLineNumber) +# define ALIGNED_FREE(Ptr) _aligned_free(Ptr) #elif defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__) - return _aligned_malloc(Size, Alignment); +# define ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber) _aligned_malloc(Size, Alignment) +# define ALIGNED_FREE(Ptr) _aligned_free(Ptr) #else - return aligned_alloc(Alignment, Size); +# define ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber) aligned_alloc(Alignment, Size) +# define ALIGNED_FREE(Ptr) free(Ptr) #endif + +void* DefaultRawMemoryAllocator::AllocateAligned(size_t Size, size_t Alignment, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber) +{ + VERIFY_EXPR(Size > 0 && Alignment > 0); + Size = AlignUp(Size, Alignment); + return ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber); } void DefaultRawMemoryAllocator::FreeAligned(void* Ptr) { -#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__) - _aligned_free(Ptr); -#else - free(Ptr); -#endif + ALIGNED_FREE(Ptr); } DefaultRawMemoryAllocator& DefaultRawMemoryAllocator::GetAllocator()