Skip to content

Commit 39d2dab

Browse files
DefaultRawMemoryAllocator: refactoring to reduce the number of #if conditions
1 parent 73c010b commit 39d2dab

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

Common/src/DefaultRawMemoryAllocator.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,34 @@ void DefaultRawMemoryAllocator::Free(void* Ptr)
5858
free(Ptr);
5959
}
6060

61-
void* DefaultRawMemoryAllocator::AllocateAligned(size_t Size, size_t Alignment, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
62-
{
63-
VERIFY_EXPR(Size > 0 && Alignment > 0);
64-
Size = AlignUp(Size, Alignment);
61+
#ifdef ALIGNED_MALLOC
62+
# undef ALIGNED_MALLOC
63+
#endif
64+
#ifdef ALIGNED_FREE
65+
# undef ALIGNED_FREE
66+
#endif
67+
6568
#ifdef USE_CRT_MALLOC_DBG
66-
return _aligned_malloc_dbg(Size, Alignment, dbgFileName, dbgLineNumber);
69+
# define ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber) _aligned_malloc_dbg(Size, Alignment, dbgFileName, dbgLineNumber)
70+
# define ALIGNED_FREE(Ptr) _aligned_free(Ptr)
6771
#elif defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__)
68-
return _aligned_malloc(Size, Alignment);
72+
# define ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber) _aligned_malloc(Size, Alignment)
73+
# define ALIGNED_FREE(Ptr) _aligned_free(Ptr)
6974
#else
70-
return aligned_alloc(Alignment, Size);
75+
# define ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber) aligned_alloc(Alignment, Size)
76+
# define ALIGNED_FREE(Ptr) free(Ptr)
7177
#endif
78+
79+
void* DefaultRawMemoryAllocator::AllocateAligned(size_t Size, size_t Alignment, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
80+
{
81+
VERIFY_EXPR(Size > 0 && Alignment > 0);
82+
Size = AlignUp(Size, Alignment);
83+
return ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber);
7284
}
7385

7486
void DefaultRawMemoryAllocator::FreeAligned(void* Ptr)
7587
{
76-
#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__)
77-
_aligned_free(Ptr);
78-
#else
79-
free(Ptr);
80-
#endif
88+
ALIGNED_FREE(Ptr);
8189
}
8290

8391
DefaultRawMemoryAllocator& DefaultRawMemoryAllocator::GetAllocator()

0 commit comments

Comments
 (0)