forked from geofflangdale/simdcsv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mem_util.h
32 lines (28 loc) · 788 Bytes
/
mem_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef MEM_UTIL_H
#define MEM_UTIL_H
#include <stdlib.h>
// portable version of posix_memalign
static inline void *aligned_malloc(size_t alignment, size_t size) {
void *p;
#ifdef _MSC_VER
p = _aligned_malloc(size, alignment);
#elif defined(__MINGW32__) || defined(__MINGW64__)
p = __mingw_aligned_malloc(size, alignment);
#else
// somehow, if this is used before including "x86intrin.h", it creates an
// implicit defined warning.
if (posix_memalign(&p, alignment, size) != 0) { return 0; }
#endif
return p;
}
static inline void aligned_free(void *memblock) {
if(memblock == 0) { return; }
#ifdef _MSC_VER
_aligned_free(memblock);
#elif defined(__MINGW32__) || defined(__MINGW64__)
__mingw_aligned_free(memblock);
#else
free(memblock);
#endif
}
#endif