Skip to content

Commit

Permalink
Merge pull request #26 from mmozeiko/master
Browse files Browse the repository at this point in the history
Aligned allocations on Windows also for clang/gcc
  • Loading branch information
cmuratori committed Oct 27, 2018
2 parents fa60ccc + 9470071 commit 67ac7f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions meow_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include <stdlib.h>
#include <memory.h>

#if _MSC_VER
#if _WIN32
// NOTE(casey): Sadly, Visual Studio STILL doesn't seem to support standard
// C, so you have to use their weird aligned malloc.
// NOTE(mmozeiko): gcc/clang on Windows also should use these functions
#define aligned_alloc(a,b) _aligned_malloc(b,a)
#define free _aligned_free
#endif
#if __APPLE__
#elif __APPLE__
// NOTE: Apple Xcode/clang seems to not include aligned_alloc in the standard
// library, so emulate via posix_memalign.
static void* aligned_alloc(size_t alignment, size_t size)
Expand Down
10 changes: 7 additions & 3 deletions utils/meow_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <intrin.h>
#define TRY __try
#define CATCH __except(1)
#define malloc(a) _aligned_malloc(a,16)
#define aligned_alloc(a,b) _aligned_malloc(b,a)
#define free _aligned_free
#else
#include <x86intrin.h>
#define TRY try
Expand All @@ -29,6 +26,13 @@ static void* aligned_alloc(size_t alignment, size_t size)
posix_memalign(&pointer, alignment, size);
return pointer;
}
#elif _WIN32
// NOTE(mmozeiko): MSVC/gcc/clang on Windows should use _aligned_...
// functions from functions stdlib.h
#include <stdlib.h>
#define malloc(a) _aligned_malloc(a,16)
#define aligned_alloc(a,b) _aligned_malloc(b,a)
#define free _aligned_free
#endif

#include "meow_hash.h"
Expand Down

0 comments on commit 67ac7f3

Please sign in to comment.