comparison src/core/ngx_palloc.c @ 860:201d017ea470

slab allocator in shared memory
author Igor Sysoev <igor@sysoev.ru>
date Mon, 20 Nov 2006 08:51:45 +0000
parents 65bf042c0b4f
children 87f456ff13b0
comparison
equal deleted inserted replaced
859:d1e8c59a50ee 860:201d017ea470
191 191
192 return p; 192 return p;
193 } 193 }
194 194
195 195
196 void *
197 ngx_shalloc(size_t size)
198 {
199 u_char *p;
200
201 if (size < sizeof(int) || (size & 1)) {
202 p = ngx_cycle->shm_last;
203
204 } else {
205 p = ngx_align_ptr(ngx_cycle->shm_last, NGX_ALIGNMENT);
206 }
207
208 if ((size_t) (ngx_cycle->shm_end - p) >= size) {
209 ngx_cycle->shm_last = p + size;
210 return p;
211 }
212
213 ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, 0,
214 "allocation of %uz bytes in shared memory failed, "
215 "only %uz are available",
216 size, ngx_cycle->shm_end - ngx_cycle->shm_last);
217
218 return NULL;
219 }
220
221
222 void *
223 ngx_shcalloc(size_t size)
224 {
225 void *p;
226
227 p = ngx_shalloc(size);
228 if (p) {
229 ngx_memzero(p, size);
230 }
231
232 return p;
233 }
234
235
236 ngx_pool_cleanup_t * 196 ngx_pool_cleanup_t *
237 ngx_pool_cleanup_add(ngx_pool_t *p, size_t size) 197 ngx_pool_cleanup_add(ngx_pool_t *p, size_t size)
238 { 198 {
239 ngx_pool_cleanup_t *c; 199 ngx_pool_cleanup_t *c;
240 200