comparison src/core/ngx_palloc.c @ 2039:4d8140271204

*) 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()
author Igor Sysoev <igor@sysoev.ru>
date Tue, 27 May 2008 09:37:40 +0000
parents d65172100f6b
children 2a92804f4109
comparison
equal deleted inserted replaced
2038:93a0d80fdce6 2039:4d8140271204
97 p = pool->current; 97 p = pool->current;
98 current = p; 98 current = p;
99 99
100 for ( ;; ) { 100 for ( ;; ) {
101 101
102 #if (NGX_HAVE_NONALIGNED)
103
104 /* 102 /*
105 * allow non-aligned memory blocks for small allocations (1, 2, 103 * allow non-aligned memory blocks for small allocations (1, 2,
106 * or 3 bytes) and for odd length strings (struct's have aligned 104 * or 3 bytes) and for odd length strings (struct's have aligned
107 * size) 105 * size)
108 */ 106 */
109 107
110 if (size < sizeof(int) || (size & 1)) { 108 if (size < sizeof(int) || (size & 1)) {
111 m = p->last; 109 m = p->last;
112 110
113 } else 111 } else {
114 #endif
115
116 {
117 m = ngx_align_ptr(p->last, NGX_ALIGNMENT); 112 m = ngx_align_ptr(p->last, NGX_ALIGNMENT);
118 } 113 }
119 114
120 if ((size_t) (p->end - m) >= size) { 115 if ((size_t) (p->end - m) >= size) {
121 p->last = m + size; 116 p->last = m + size;
172 large->alloc = p; 167 large->alloc = p;
173 large->next = pool->large; 168 large->next = pool->large;
174 pool->large = large; 169 pool->large = large;
175 170
176 return p; 171 return p;
172 }
173
174
175 void *
176 ngx_palloc_aligned(ngx_pool_t *pool, size_t size)
177 {
178 if (size & 1) {
179 size++;
180 }
181
182 return ngx_palloc(pool, size);
177 } 183 }
178 184
179 185
180 ngx_int_t 186 ngx_int_t
181 ngx_pfree(ngx_pool_t *pool, void *p) 187 ngx_pfree(ngx_pool_t *pool, void *p)