mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
*) 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()
This commit is contained in:
parent
626cd7e7be
commit
2d951bfa41
@ -99,8 +99,6 @@ ngx_palloc(ngx_pool_t *pool, size_t size)
|
|||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
|
|
||||||
#if (NGX_HAVE_NONALIGNED)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* allow non-aligned memory blocks for small allocations (1, 2,
|
* allow non-aligned memory blocks for small allocations (1, 2,
|
||||||
* or 3 bytes) and for odd length strings (struct's have aligned
|
* 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)) {
|
if (size < sizeof(int) || (size & 1)) {
|
||||||
m = p->last;
|
m = p->last;
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
#endif
|
|
||||||
|
|
||||||
{
|
|
||||||
m = ngx_align_ptr(p->last, NGX_ALIGNMENT);
|
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_int_t
|
||||||
ngx_pfree(ngx_pool_t *pool, void *p)
|
ngx_pfree(ngx_pool_t *pool, void *p)
|
||||||
{
|
{
|
||||||
|
@ -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_destroy_pool(ngx_pool_t *pool);
|
||||||
|
|
||||||
void *ngx_palloc(ngx_pool_t *pool, size_t size);
|
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);
|
void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
|
||||||
ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p);
|
ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p);
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ ngx_regex_malloc(size_t size)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (pool) {
|
if (pool) {
|
||||||
return ngx_palloc(pool, size);
|
return ngx_palloc_aligned(pool, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1024,12 +1024,15 @@ ngx_http_create_locations_tree(ngx_conf_t *cf, ngx_queue_t *locations,
|
|||||||
lq = (ngx_http_location_queue_t *) q;
|
lq = (ngx_http_location_queue_t *) q;
|
||||||
len = lq->name->len - prefix;
|
len = lq->name->len - prefix;
|
||||||
|
|
||||||
node = ngx_pcalloc(cf->pool,
|
node = ngx_palloc_aligned(cf->pool,
|
||||||
offsetof(ngx_http_location_tree_node_t, name) + len);
|
offsetof(ngx_http_location_tree_node_t, name) + len);
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node->left = NULL;
|
||||||
|
node->right = NULL;
|
||||||
|
node->tree = NULL;
|
||||||
node->exact = lq->exact;
|
node->exact = lq->exact;
|
||||||
node->inclusive = lq->inclusive;
|
node->inclusive = lq->inclusive;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user