/
array_and_hash.c
43 lines (36 loc) · 1023 Bytes
/
array_and_hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include "ngx_config.h"
#include "ngx_conf_file.h"
#include "nginx.h"
#include "ngx_core.h"
#include "ngx_string.h"
#include "ngx_palloc.h"
#include "ngx_array.h"
volatile ngx_cycle_t *ngx_cycle;
void ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
const char *fmt, ...)
{
}
int main(void) {
ngx_pool_t *pool;
ngx_array_t *arr;
int n;
int *ele;
pool = ngx_create_pool(4000, NULL);
arr = ngx_array_create(pool, 10, sizeof(ngx_uint_t));
for (n=0; n < 5; n++) {
ele = (int *)ngx_array_push(arr);
*ele = n;
printf("new element %d added\n", n);
}
printf("arr->nelts is %d, arr->nalloc = %d\n", arr->nelts, arr->nalloc);
for (n=5; n < 15; n++) {
ele = (int *)ngx_array_push(arr);
*ele = n;
printf("new element %d added\n", n);
}
printf("arr->nelts is %d, arr->nalloc = %d\n", arr->nelts, arr->nalloc);
ngx_array_destroy(arr);
ngx_destroy_pool(pool);
return 0;
}