blob: 0179b387cc393937cf8ab2bb73a625a82ff8325a [file] [log] [blame]
njn9a55ee82009-04-15 05:35:00 +00001// Replacement for malloc.h which factors out platform differences.
2
3#include <stdlib.h>
njnf76d27a2009-05-28 01:53:07 +00004#if defined(VGO_darwin)
5# include <malloc/malloc.h>
6#else
7# include <malloc.h>
8#endif
njn9a55ee82009-04-15 05:35:00 +00009
10#include <assert.h>
11
12// Allocates a 16-aligned block. Asserts if the allocation fails.
13__attribute__((unused))
14static void* memalign16(size_t szB)
15{
16 void* x;
njnf76d27a2009-05-28 01:53:07 +000017#if defined(VGO_darwin)
18 // Darwin lacks memalign, but its malloc is always 16-aligned anyway.
19 x = malloc(szB);
20#else
njn9a55ee82009-04-15 05:35:00 +000021 x = memalign(16, szB);
njnf76d27a2009-05-28 01:53:07 +000022#endif
njn9a55ee82009-04-15 05:35:00 +000023 assert(x);
24 assert(0 == ((16-1) & (unsigned long)x));
25 return x;
26}
27