Mercurial > hg > nginx-quic
comparison src/core/ngx_alloc.c @ 26:53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 15 Dec 2002 06:25:09 +0000 |
parents | 4f3879d9b6f6 |
children | 83fa61cd3d2f |
comparison
equal
deleted
inserted
replaced
25:a8b156554dfe | 26:53cb81681040 |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 | 3 |
4 #include <ngx_errno.h> | 4 #include <ngx_errno.h> |
5 #include <ngx_log.h> | 5 #include <ngx_log.h> |
6 #include <ngx_string.h> | |
6 #include <ngx_alloc.h> | 7 #include <ngx_alloc.h> |
7 | 8 |
8 | 9 |
9 void *ngx_alloc(size_t size, ngx_log_t *log) | 10 void *ngx_alloc(size_t size, ngx_log_t *log) |
10 { | 11 { |
13 p = malloc(size); | 14 p = malloc(size); |
14 if (p == NULL) | 15 if (p == NULL) |
15 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, | 16 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, |
16 "malloc() %d bytes failed", size); | 17 "malloc() %d bytes failed", size); |
17 | 18 |
18 ngx_log_debug(log, "malloc: %x:%d" _ p _ size); | 19 ngx_log_debug(log, "malloc: %08x:%d" _ p _ size); |
19 | 20 |
20 return p; | 21 return p; |
21 } | 22 } |
22 | 23 |
23 void *ngx_calloc(size_t size, ngx_log_t *log) | 24 void *ngx_calloc(size_t size, ngx_log_t *log) |
50 { | 51 { |
51 ngx_pool_t *p, *n; | 52 ngx_pool_t *p, *n; |
52 ngx_pool_large_t *l; | 53 ngx_pool_large_t *l; |
53 | 54 |
54 for (l = pool->large; l; l = l->next) { | 55 for (l = pool->large; l; l = l->next) { |
55 ngx_log_debug(pool->log, "free: %x" _ l->alloc); | 56 ngx_log_debug(pool->log, "free: %08x" _ l->alloc); |
56 free(l->alloc); | 57 free(l->alloc); |
57 } | 58 } |
58 | 59 |
59 for (p = pool, n = pool->next; /* void */; p = n, n = n->next) { | 60 for (p = pool, n = pool->next; /* void */; p = n, n = n->next) { |
60 ngx_log_debug(pool->log, "free: %x" _ p); | 61 ngx_log_debug(pool->log, "free: %08x" _ p); |
61 free(p); | 62 free(p); |
62 | 63 |
63 if (n == NULL) | 64 if (n == NULL) |
64 break; | 65 break; |
65 } | 66 } |
72 ngx_pool_large_t *large, *last; | 73 ngx_pool_large_t *large, *last; |
73 | 74 |
74 if (size <= NGX_MAX_ALLOC_FROM_POOL) { | 75 if (size <= NGX_MAX_ALLOC_FROM_POOL) { |
75 | 76 |
76 for (p = pool, n = pool->next; /* void */; p = n, n = n->next) { | 77 for (p = pool, n = pool->next; /* void */; p = n, n = n->next) { |
77 if ((size_t) (p->end - p->last) >= size) { | 78 if ((size_t) (p->end - ngx_align(p->last)) >= size) { |
78 m = p->last; | 79 m = ngx_align(p->last); |
79 p->last += size; | 80 p->last = ngx_align(p->last); |
81 p->last += size ; | |
80 | 82 |
81 return m; | 83 return m; |
82 } | 84 } |
83 | 85 |
84 if (n == NULL) | 86 if (n == NULL) |