1 #include "[SSEMath.h]"2 #include "[MathFunc.h]"3 #include <stdint.h>4 #include <stdlib.h>5 6 using namespace std;7 8 [MATH_BEGIN_NAMESPACE]9 10 void *[AlignedMalloc](size_t size, size_t alignment)11 {12 alignment = alignment > 0 ? alignment : 1;13 size += alignment;14 15 uintptr_t ptr = (uintptr_t)malloc(size);16 #ifndef __clang_analyzer__ // Hide clang analyzer false positive: Memory is never released; potential leak of memory pointed to by 'ptr'17 if (!ptr)18 return 0;19 ++ptr; 20 ptrdiff_t incr = (alignment - (ptr & (alignment-1))) & (alignment-1);21 ptr += incr;22 (([u8]*)ptr)[-1] = ([u8])(incr+1);23 #endif24 [assert](ptr % alignment == 0);25 return (void*)ptr;26 }27 28 void [AlignedFree](void *ptr)29 {30 if (!ptr)31 return;32 [u8] *p = ([u8]*)ptr;33 p -= p[-1];34 free(p);35 }36 37 [MATH_END_NAMESPACE] Go back to previous page