From 2d951bfa417f0e125708d5dac64f2f0b91610e07 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 27 May 2008 09:37:40 +0000 Subject: *) add ngx_palloc_aligned() to allocate explicitlty aligned memory *) allows non-aligned memory blocks for small allocations and for odd length strings on all platforms *) use ngx_palloc_aligned() --- src/core/ngx_palloc.c | 18 ++++++++++++------ src/core/ngx_palloc.h | 1 + src/core/ngx_regex.c | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/core') diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c index 4cf7e8a4b..130c67056 100644 --- a/src/core/ngx_palloc.c +++ b/src/core/ngx_palloc.c @@ -99,8 +99,6 @@ ngx_palloc(ngx_pool_t *pool, size_t size) for ( ;; ) { -#if (NGX_HAVE_NONALIGNED) - /* * allow non-aligned memory blocks for small allocations (1, 2, * or 3 bytes) and for odd length strings (struct's have aligned @@ -110,10 +108,7 @@ ngx_palloc(ngx_pool_t *pool, size_t size) if (size < sizeof(int) || (size & 1)) { m = p->last; - } else -#endif - - { + } else { m = ngx_align_ptr(p->last, NGX_ALIGNMENT); } @@ -177,6 +172,17 @@ ngx_palloc(ngx_pool_t *pool, size_t size) } +void * +ngx_palloc_aligned(ngx_pool_t *pool, size_t size) +{ + if (size & 1) { + size++; + } + + return ngx_palloc(pool, size); +} + + ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p) { diff --git a/src/core/ngx_palloc.h b/src/core/ngx_palloc.h index 13443d7dd..11e2b41da 100644 --- a/src/core/ngx_palloc.h +++ b/src/core/ngx_palloc.h @@ -69,6 +69,7 @@ ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log); void ngx_destroy_pool(ngx_pool_t *pool); void *ngx_palloc(ngx_pool_t *pool, size_t size); +void *ngx_palloc_aligned(ngx_pool_t *pool, size_t size); void *ngx_pcalloc(ngx_pool_t *pool, size_t size); ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p); diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c index be2dae79b..fb12ab16b 100644 --- a/src/core/ngx_regex.c +++ b/src/core/ngx_regex.c @@ -165,7 +165,7 @@ ngx_regex_malloc(size_t size) #endif if (pool) { - return ngx_palloc(pool, size); + return ngx_palloc_aligned(pool, size); } return NULL; -- cgit