Skip to content

Commit

Permalink
memory: AlignedAlloc: fallback to aligned_alloc()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sephiroth99 authored and benvanik committed Sep 22, 2015
1 parent 83f3d52 commit ff7c755
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/xenia/base/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ff7c755

Please sign in to comment.