Klaus Demo nginx / 2d951bf
*) 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() Igor Sysoev 14 years ago
4 changed file(s) with 19 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
9898
9999 for ( ;; ) {
100100
101 #if (NGX_HAVE_NONALIGNED)
102
103101 /*
104102 * allow non-aligned memory blocks for small allocations (1, 2,
105103 * or 3 bytes) and for odd length strings (struct's have aligned
109107 if (size < sizeof(int) || (size & 1)) {
110108 m = p->last;
111109
112 } else
113 #endif
114
115 {
110 } else {
116111 m = ngx_align_ptr(p->last, NGX_ALIGNMENT);
117112 }
118113
173168 pool->large = large;
174169
175170 return p;
171 }
172
173
174 void *
175 ngx_palloc_aligned(ngx_pool_t *pool, size_t size)
176 {
177 if (size & 1) {
178 size++;
179 }
180
181 return ngx_palloc(pool, size);
176182 }
177183
178184
6868 void ngx_destroy_pool(ngx_pool_t *pool);
6969
7070 void *ngx_palloc(ngx_pool_t *pool, size_t size);
71 void *ngx_palloc_aligned(ngx_pool_t *pool, size_t size);
7172 void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
7273 ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p);
7374
164164 #endif
165165
166166 if (pool) {
167 return ngx_palloc(pool, size);
167 return ngx_palloc_aligned(pool, size);
168168 }
169169
170170 return NULL;
10231023 lq = (ngx_http_location_queue_t *) q;
10241024 len = lq->name->len - prefix;
10251025
1026 node = ngx_pcalloc(cf->pool,
1027 offsetof(ngx_http_location_tree_node_t, name) + len);
1026 node = ngx_palloc_aligned(cf->pool,
1027 offsetof(ngx_http_location_tree_node_t, name) + len);
10281028 if (node == NULL) {
10291029 return NULL;
10301030 }
10311031
1032 node->left = NULL;
1033 node->right = NULL;
1034 node->tree = NULL;
10321035 node->exact = lq->exact;
10331036 node->inclusive = lq->inclusive;
10341037