From e921387af8d68b18babcd7e098b97479965b7663 Mon Sep 17 00:00:00 2001 From: Martin Baute Date: Sun, 13 Mar 2016 09:54:12 +0100 Subject: [PATCH] Pulled in aligned_alloc from dlmalloc.c (dlmemalign). --- includes/stdlib.h | 13 ++++++++++--- opt/dlmalloc/dlmalloc.c | 30 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/includes/stdlib.h b/includes/stdlib.h index 157ebee..b94ceaf 100644 --- a/includes/stdlib.h +++ b/includes/stdlib.h @@ -95,19 +95,26 @@ void srand( unsigned int seed ) _PDCLIB_nothrow; /* Memory management functions */ -/* Allocate a chunk of heap memory of given size. If request could not be +/* Allocate a chunk of memory of given size. If request could not be satisfied, return NULL. Otherwise, return a pointer to the allocated memory. Memory contents are undefined. */ void * malloc( size_t size ) _PDCLIB_nothrow; -/* Allocate a chunk of heap memory that is large enough to hold nmemb elements - of the given size, and zero-initialize that memory. If request could not be +/* Allocate a chunk of memory that is large enough to hold nmemb elements of + the given size, and zero-initialize that memory. If request could not be satisfied, return NULL. Otherwise, return a pointer to the allocated memory. */ void * calloc( size_t nmemb, size_t size ) _PDCLIB_nothrow; +/* Allocate a chunk of memory of given size, with specified alignment (which + must be a power of two; if it is not, the next greater power of two is + used). If request could not be satisfied, return NULL. Otherwise, return + a pointer to the allocated memory. +*/ +void * aligned_alloc( size_t alignment, size_t size ) _PDCLIB_nothrow; + /* De-allocate a chunk of heap memory previously allocated using malloc(), calloc(), or realloc(), and pointed to by ptr. If ptr does not match a pointer previously returned by the mentioned allocation functions, or diff --git a/opt/dlmalloc/dlmalloc.c b/opt/dlmalloc/dlmalloc.c index 865b5b9..dd1126a 100644 --- a/opt/dlmalloc/dlmalloc.c +++ b/opt/dlmalloc/dlmalloc.c @@ -814,7 +814,7 @@ extern "C" { #define dlcalloc calloc #define dlfree free #define dlmalloc malloc -#define dlmemalign memalign +#define dlmemalign aligned_alloc #define dlposix_memalign posix_memalign #define dlrealloc realloc #define dlrealloc_in_place realloc_in_place @@ -893,6 +893,20 @@ DLMALLOC_EXPORT void* dlcalloc(size_t, size_t); */ DLMALLOC_EXPORT void* dlrealloc(void*, size_t); +/* + memalign(size_t alignment, size_t n); + Returns a pointer to a newly allocated chunk of n bytes, aligned + in accord with the alignment argument. + + The alignment argument should be a power of two. If the argument is + not a power of two, the nearest greater power is used. + 8-byte alignment is guaranteed by normal malloc calls, so don't + bother calling memalign with an argument of 8 or less. + + Overreliance on memalign is a sure way to fragment space. +*/ +DLMALLOC_EXPORT void* dlmemalign(size_t, size_t); + #endif /* @@ -910,20 +924,6 @@ DLMALLOC_EXPORT void* dlrealloc(void*, size_t); */ DLMALLOC_EXPORT void* dlrealloc_in_place(void*, size_t); -/* - memalign(size_t alignment, size_t n); - Returns a pointer to a newly allocated chunk of n bytes, aligned - in accord with the alignment argument. - - The alignment argument should be a power of two. If the argument is - not a power of two, the nearest greater power is used. - 8-byte alignment is guaranteed by normal malloc calls, so don't - bother calling memalign with an argument of 8 or less. - - Overreliance on memalign is a sure way to fragment space. -*/ -DLMALLOC_EXPORT void* dlmemalign(size_t, size_t); - /* int posix_memalign(void** pp, size_t alignment, size_t n); Allocates a chunk of n bytes, aligned in accord with the alignment -- 2.40.0