Nginx Source Code First reading (3)--let troubles start from main ngx_pool

Source: Internet
Author: User
Nginx_pool provides a resource management mechanism (such as memory, files, etc.), making the use and release of resources Unified, eliminating the many problems of resource release, developers only need to apply in memory, not too much consideration of memory release and other issues, greatly improve the efficiency of development.

For example, establishing a pool of memory uniformly in a specific lifecycle (such as allocating a 1024B-sized memory pool at the beginning of the main function system), requiring memory to be uniformly allocated in memory pool, and freeing memory pool memory when appropriate (call Ngx_destroy_ when closing an HTTP link) Pool for destruction).

typedefstructngx_pool_s ngx_pool_t;typedefstructngx_pool_cleanup_s ngx_pool_cleanup_t;typedefvoid(*NGX_POOL_CLEANUP_PT) (void*data);structngx_pool_cleanup_s {NGX_POOL_CLEANUP_PT handler;void*data; ngx_pool_cleanup_t *next;};typedefstructNgx_pool_large_s ngx_pool_large_t;structngx_pool_large_s {ngx_pool_large_t *next;void*alloc;};typedefstruct{U_char *last; U_char *end;/ * refers to the allocation location of the current memory pool (the next time the memory is allocated) and the end position (memory is exhausted) * if ((size_t) (p->d.end-m) >= size) {P->d.last =           m + size;       return m; }       */ngx_pool_t *next;/* Point to the next pool memory block (call Palloc_block to create a new pool and allocate memory when pool memory is low) * psize = (size_t) (Pool->d.end-(U_char *) pool)       ;       m = Ngx_memalign (Ngx_pool_alignment, psize, Pool->log);       New = (ngx_pool_t *) m;     P->d.next = new; */Ngx_uint_t failed;/ * Current block memory allocation failure number, from this code to see should be used to record the memory block to create the search location?           Because it records that there is not enough memory from this piece, and failed is present to redirect current, reduce the number of traversal (within 4) * for (p = pool->current; p->d.next; p = p->d.next) {          if (p->d.failed++ > 4) {pool->current = p->d.next; }       }     */} ngx_pool_data_t;structngx_pool_s {ngx_pool_data_t D;    size_t Max;    ngx_pool_t *current;    Ngx_chain_t *chain;    ngx_pool_large_t *large;    ngx_pool_cleanup_t *cleanup; ngx_log_t *Log;};

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above introduction of Nginx source code first read (3)-Let the trouble from main start Ngx_pool, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.