src/core/ngx_palloc.h - nginx-1.7.10

Data types defined

Macros defined

Source code


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


  5. #ifndef _NGX_PALLOC_H_INCLUDED_
  6. #define _NGX_PALLOC_H_INCLUDED_


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


  9. /*
  10. * NGX_MAX_ALLOC_FROM_POOL should be (ngx_pagesize - 1), i.e. 4095 on x86.
  11. * On Windows NT it decreases a number of locked pages in a kernel.
  12. */
  13. #define NGX_MAX_ALLOC_FROM_POOL  (ngx_pagesize - 1)

  14. #define NGX_DEFAULT_POOL_SIZE    (16 * 1024)

  15. #define NGX_POOL_ALIGNMENT       16
  16. #define NGX_MIN_POOL_SIZE                                                     \
  17.     ngx_align((sizeof(ngx_pool_t) + 2 * sizeof(ngx_pool_large_t)),            \
  18.               NGX_POOL_ALIGNMENT)


  19. typedef void (*ngx_pool_cleanup_pt)(void *data);

  20. typedef struct ngx_pool_cleanup_s  ngx_pool_cleanup_t;

  21. struct ngx_pool_cleanup_s {
  22.     ngx_pool_cleanup_pt   handler;
  23.     void                 *data;
  24.     ngx_pool_cleanup_t   *next;
  25. };


  26. typedef struct ngx_pool_large_s  ngx_pool_large_t;

  27. struct ngx_pool_large_s {
  28.     ngx_pool_large_t     *next;
  29.     void                 *alloc;
  30. };


  31. typedef struct {
  32.     u_char               *last;
  33.     u_char               *end;
  34.     ngx_pool_t           *next;
  35.     ngx_uint_t            failed;
  36. } ngx_pool_data_t;


  37. struct ngx_pool_s {
  38.     ngx_pool_data_t       d;
  39.     size_t                max;
  40.     ngx_pool_t           *current;
  41.     ngx_chain_t          *chain;
  42.     ngx_pool_large_t     *large;
  43.     ngx_pool_cleanup_t   *cleanup;
  44.     ngx_log_t            *log;
  45. };


  46. typedef struct {
  47.     ngx_fd_t              fd;
  48.     u_char               *name;
  49.     ngx_log_t            *log;
  50. } ngx_pool_cleanup_file_t;


  51. void *ngx_alloc(size_t size, ngx_log_t *log);
  52. void *ngx_calloc(size_t size, ngx_log_t *log);

  53. ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log);
  54. void ngx_destroy_pool(ngx_pool_t *pool);
  55. void ngx_reset_pool(ngx_pool_t *pool);

  56. void *ngx_palloc(ngx_pool_t *pool, size_t size);
  57. void *ngx_pnalloc(ngx_pool_t *pool, size_t size);
  58. void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
  59. void *ngx_pmemalign(ngx_pool_t *pool, size_t size, size_t alignment);
  60. ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p);


  61. ngx_pool_cleanup_t *ngx_pool_cleanup_add(ngx_pool_t *p, size_t size);
  62. void ngx_pool_run_cleanup_file(ngx_pool_t *p, ngx_fd_t fd);
  63. void ngx_pool_cleanup_file(void *data);
  64. void ngx_pool_delete_file(void *data);


  65. #endif /* _NGX_PALLOC_H_INCLUDED_ */