• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Replacement for malloc.h which factors out platform differences.
2 
3 #include <stdlib.h>
4 #if defined(VGO_darwin)
5 #  include <malloc/malloc.h>
6 #else
7 #  include <malloc.h>
8 #endif
9 
10 #include <assert.h>
11 
12 // Allocates a 16-aligned block.  Asserts if the allocation fails.
13 __attribute__((unused))
memalign16(size_t szB)14 static void* memalign16(size_t szB)
15 {
16    void* x;
17 #if defined(VGO_darwin)
18    // Darwin lacks memalign, but its malloc is always 16-aligned anyway.
19    x = malloc(szB);
20 #else
21    x = memalign(16, szB);
22 #endif
23    assert(x);
24    assert(0 == ((16-1) & (unsigned long)x));
25    return x;
26 }
27 
28