commit 699923bd024405432fe5f1529431f85f8a50b97f
parent 9c9ce42f16b311175630b1a1eee89c880e982b7f
Author: vaplv <vaplv@free.fr>
Date: Thu, 19 Apr 2018 12:09:32 +0200
Fix the default aligned memory allocation on CL compiler
Diffstat:
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/mem_allocator.c b/src/mem_allocator.c
@@ -124,9 +124,13 @@ mem_alloc_aligned(const size_t size, const size_t alignment)
#if defined(OS_WINDOWS)
mem = _aligned_offset_malloc
(size + MEM_HEADER_SIZE, alignment, MEM_HEADER_SIZE);
- ((size_t*)mem)[0] = alignment;
- ((size_t*)mem)[1] = size + MEM_HEADER_SIZE;
- mem = ((char*)mem) + MEM_HEADER_SIZE;
+ if(mem) {
+ ((size_t*)mem)[0] = alignment;
+ ((size_t*)mem)[1] = size + MEM_HEADER_SIZE;
+ mem = ((char*)mem) + MEM_HEADER_SIZE;
+ ATOMIC_ADD(&g_alloc_counter.allocated_size, mem_size(mem));
+ ATOMIC_INCR(&g_alloc_counter.nb_allocs);
+ }
#elif defined(OS_UNIX) || defined(OS_MACH)
const int result = posix_memalign
(&mem, (alignment < sizeof(void*)) ? sizeof(void*) : alignment, size);
@@ -134,13 +138,13 @@ mem_alloc_aligned(const size_t size, const size_t alignment)
/* The following assert may not occur due to previous conditions */
ASSERT(result != EINVAL);
ASSERT((result != ENOMEM) || (mem == NULL));
-#else
- #error "Unsupported OS"
-#endif
if(mem) {
ATOMIC_ADD(&g_alloc_counter.allocated_size, mem_size(mem));
ATOMIC_INCR(&g_alloc_counter.nb_allocs);
}
+#else
+ #error "Unsupported OS"
+#endif
}
return mem;
}