: This article mainly introduces the nginx source code first read (3) -- Let the troubles start from main ngx_pool. if you are interested in PHP tutorials, refer to it. Nginx_pool provides a resource management mechanism (such as memory and files), which allows you to use and release resources in a unified manner, eliminating many problems related to resource release, developers only need to apply for memory when they need it. they do not need to worry too much about memory release and other issues, which greatly improves the development efficiency.
For example, if a memory pool is set up in a specific life cycle (for example, a memory pool of B is allocated at the initial stage of the main function system), the memory in the memory pool needs to be allocated in a unified manner, release the memory of the memory pool when appropriate (for example, call ngx_destroy_pool to destroy the memory pool when the http link is closed ).
Typedefstruct ngx_pool_s ngx_pool_t; typedefstruct skip; typedefvoid (* handle) (void * data); struct skip {handle handler; void * data; expect * next;}; typedefstruct skip; struct ngx_pool_large_s {ngx_pool_large_t * next; void * alloc;}; typedefstruct {u_char * last; u_char * end;/* indicates the allocation bit of the current memory pool respectively. Set (memory allocated from last time) and end position (memory used up) * 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 (when the pool memory is insufficient, palloc_block will be called to create a new pool and allocate memory) * 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;/* Number of times the current block memory allocation failed. from this code, the current is used to record the memory block to be created? Because it records that the memory is insufficient from this block, and failed exists to redirect current, reducing the traversal quantity (within 4) * for (p = pool-> current; p-> d. next; p = p-> d. next) {if (p-> d. failed ++> 4) {pool-> current = p-> d. next ;}} */} struct; struct ngx_pool_s {mongod; size_t max; ngx_pool_t * current; ngx_chain_t * chain; worker * large; worker * 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) ;}) ;}; script
The above introduces the nginx source code first read (3) -- Let the troubles start from main ngx_pool, including the content, hope to be helpful to friends interested in PHP tutorials.