Implement aligned_alloc().

Implement aligned_alloc(), which was added in the C11 standard.  The
function is weakly specified to the point that a minimally compliant
implementation would be painful to use (size must be an integral
multiple of alignment!), which in practice makes posix_memalign() a
safer choice.
This commit is contained in:
Jason Evans
2012-03-13 12:55:21 -07:00
parent 4c2faa8a7c
commit 0a0bbf63e5
8 changed files with 218 additions and 14 deletions

View File

@@ -43,6 +43,7 @@ void *je_malloc(size_t size) JEMALLOC_ATTR(malloc);
void *je_calloc(size_t num, size_t size) JEMALLOC_ATTR(malloc);
int je_posix_memalign(void **memptr, size_t alignment, size_t size)
JEMALLOC_ATTR(nonnull(1));
void *je_aligned_alloc(size_t alignment, size_t size) JEMALLOC_ATTR(malloc);
void *je_realloc(void *ptr, size_t size);
void je_free(void *ptr);
@@ -82,6 +83,7 @@ int je_nallocm(size_t *rsize, size_t size, int flags);
#define malloc je_malloc
#define calloc je_calloc
#define posix_memalign je_posix_memalign
#define aligned_alloc je_aligned_alloc
#define realloc je_realloc
#define free je_free
#define malloc_usable_size je_malloc_usable_size
@@ -113,6 +115,7 @@ int je_nallocm(size_t *rsize, size_t size, int flags);
#undef je_malloc
#undef je_calloc
#undef je_posix_memalign
#undef je_aligned_alloc
#undef je_realloc
#undef je_free
#undef je_malloc_usable_size

View File

@@ -16,6 +16,7 @@
#undef je_malloc
#undef je_calloc
#undef je_posix_memalign
#undef je_aligned_alloc
#undef je_realloc
#undef je_free
#undef je_malloc_usable_size