memory: AlignedAlloc: fallback to aligned_alloc()

When compiling with clang++, __STDC_VERSION__ is not defined (obviously
as clang++ is not a C compiler). Because of this, check if compiling
with MSVC and fallback to the Linux implementation. If the latter is not
supported, compilation will fail, as it previously would have with the
This commit is contained in:
sephiroth99 2015-09-22 00:46:15 -04:00 committed by Ben Vanik
parent 83f3d520b2
commit ff7c755bc9
1 changed files with 6 additions and 10 deletions

View File

@ -67,25 +67,21 @@ bool Protect(void* base_address, size_t length, PageAccess access,
// The memory must be freed with AlignedFree.
template <typename T>
inline T* AlignedAlloc(size_t alignment) {
#if __STDC_VERSION__ >= 201112L
return reinterpret_cast<T*>(aligned_alloc(alignment, sizeof(T)));
#elif XE_COMPILER_MSVC
#if XE_COMPILER_MSVC
return reinterpret_cast<T*>(_aligned_malloc(sizeof(T), alignment));
#else
#error No aligned alloc.
#endif // __STDC_VERSION__ >= 201112L
return reinterpret_cast<T*>(aligned_alloc(alignment, sizeof(T)));
#endif // XE_COMPILER_MSVC
}
// Frees memory previously allocated with AlignedAlloc.
template <typename T>
void AlignedFree(T* ptr) {
#if __STDC_VERSION__ >= 201112L
free(ptr);
#elif XE_COMPILER_MSVC
#if XE_COMPILER_MSVC
_aligned_free(ptr);
#else
#error No aligned alloc.
#endif // __STDC_VERSION__ >= 201112L
free(ptr);
#endif // XE_COMPILER_MSVC
}
typedef void* FileMappingHandle;