Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
Igor Sysoev | ff8da91 | 2004-09-29 16:00:49 +0000 | [diff] [blame] | 3 | * Copyright (C) Igor Sysoev |
Igor Sysoev | d90282d | 2004-09-28 08:34:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 7 | #ifndef _NGX_ARRAY_H_INCLUDED_ |
| 8 | #define _NGX_ARRAY_H_INCLUDED_ |
| 9 | |
| 10 | |
| 11 | #include <ngx_config.h> |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 12 | #include <ngx_core.h> |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 13 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 14 | |
Igor Sysoev | 5f80078 | 2003-12-08 20:48:12 +0000 | [diff] [blame] | 15 | struct ngx_array_s { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 16 | void *elts; |
| 17 | ngx_uint_t nelts; |
| 18 | size_t size; |
| 19 | ngx_uint_t nalloc; |
| 20 | ngx_pool_t *pool; |
Igor Sysoev | 5f80078 | 2003-12-08 20:48:12 +0000 | [diff] [blame] | 21 | }; |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 22 | |
| 23 | |
Igor Sysoev | 805d9db | 2005-02-03 19:33:37 +0000 | [diff] [blame] | 24 | ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size); |
| 25 | void ngx_array_destroy(ngx_array_t *a); |
| 26 | void *ngx_array_push(ngx_array_t *a); |
| 27 | void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n); |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 28 | |
| 29 | |
Igor Sysoev | c157172 | 2005-03-19 12:38:37 +0000 | [diff] [blame] | 30 | static ngx_inline ngx_int_t |
| 31 | ngx_array_init(ngx_array_t *array, ngx_pool_t *pool, ngx_uint_t n, size_t size) |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 32 | { |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 33 | /* |
| 34 | * set "array->nelts" before "array->elts", otherwise MSVC thinks |
| 35 | * that "array->nelts" may be used without having been initialized |
| 36 | */ |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 37 | |
| 38 | array->nelts = 0; |
| 39 | array->size = size; |
| 40 | array->nalloc = n; |
| 41 | array->pool = pool; |
| 42 | |
Igor Sysoev | 899b44e | 2005-05-12 14:58:06 +0000 | [diff] [blame] | 43 | array->elts = ngx_palloc(pool, n * size); |
| 44 | if (array->elts == NULL) { |
| 45 | return NGX_ERROR; |
| 46 | } |
| 47 | |
Igor Sysoev | 980a924 | 2004-09-05 19:54:02 +0000 | [diff] [blame] | 48 | return NGX_OK; |
| 49 | } |
| 50 | |
| 51 | |
Igor Sysoev | 6de5c2c | 2002-08-06 16:39:45 +0000 | [diff] [blame] | 52 | #endif /* _NGX_ARRAY_H_INCLUDED_ */ |