src/core/ngx_array.h - nginx-1.7.10

Data types defined

Functions defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_ARRAY_H_INCLUDED_
  6. #define _NGX_ARRAY_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>


  9. typedef struct {
  10.     void        *elts;
  11.     ngx_uint_t   nelts;
  12.     size_t       size;
  13.     ngx_uint_t   nalloc;
  14.     ngx_pool_t  *pool;
  15. } ngx_array_t;


  16. ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size);
  17. void ngx_array_destroy(ngx_array_t *a);
  18. void *ngx_array_push(ngx_array_t *a);
  19. void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n);


  20. static ngx_inline ngx_int_t
  21. ngx_array_init(ngx_array_t *array, ngx_pool_t *pool, ngx_uint_t n, size_t size)
  22. {
  23.     /*
  24.      * set "array->nelts" before "array->elts", otherwise MSVC thinks
  25.      * that "array->nelts" may be used without having been initialized
  26.      */

  27.     array->nelts = 0;
  28.     array->size = size;
  29.     array->nalloc = n;
  30.     array->pool = pool;

  31.     array->elts = ngx_palloc(pool, n * size);
  32.     if (array->elts == NULL) {
  33.         return NGX_ERROR;
  34.     }

  35.     return NGX_OK;
  36. }


  37. #endif /* _NGX_ARRAY_H_INCLUDED_ */