diff --git a/skynet-src/malloc_hook.c b/skynet-src/malloc_hook.c index 7174f0a9..35d2260e 100644 --- a/skynet-src/malloc_hook.c +++ b/skynet-src/malloc_hook.c @@ -202,6 +202,13 @@ skynet_memalign(size_t alignment, size_t size) { return fill_prefix(ptr); } +void * +skynet_aligned_alloc(size_t alignment, size_t size) { + void* ptr = je_aligned_alloc(alignment, size + (PREFIX_SIZE + alignment -1) & ~(alignment-1)); + if(!ptr) malloc_oom(size); + return fill_prefix(ptr); +} + #else // for skynet_lalloc use diff --git a/skynet-src/skynet_malloc.h b/skynet-src/skynet_malloc.h index e2f0aa8d..81c1c603 100644 --- a/skynet-src/skynet_malloc.h +++ b/skynet-src/skynet_malloc.h @@ -8,6 +8,7 @@ #define skynet_realloc realloc #define skynet_free free #define skynet_memalign memalign +#define skynet_aligned_alloc aligned_alloc void * skynet_malloc(size_t sz); void * skynet_calloc(size_t nmemb,size_t size); @@ -16,5 +17,6 @@ void skynet_free(void *ptr); char * skynet_strdup(const char *str); void * skynet_lalloc(void *ptr, size_t osize, size_t nsize); // use for lua void * skynet_memalign(size_t alignment, size_t size); +void * skynet_aligned_alloc(size_t alignment, size_t size); #endif