Accept cookies for analytics, social media, and advertising, or learn more and adjust your preferences. These cookies are on by default for visitors outside the UK and EEA. Privacy Notice.
ngx_pool_cleanup_t
¶A structure containing an allocation from the pool as well as a callback handler for the user to set upon cleanup of the pool. This is for use with ngx_pool_cleanup_add()
void (*ngx_pool_cleanup_pt)(void *data) handler
The cleanup handler callback for the user to set
data
¶The data allocated from the allocation request
ngx_array_t
¶A structure containing the details of an array allocated using ngx_array_create()
. Since a continuous block is allocated it should be relative trivial to calculate where a given element in the array is based on size.
elts
¶A pointer to the elements in the array
nelts
¶The number of elements stored in the array
nalloc
¶The number of allocated items in the array
size
¶The size of each element in the array
pool
¶A pointer to the pool used for the array
ngx_list_t
¶A structure containing details of a linked-list allocated using ngx_list_create()
.
last
¶A pointer to the list part containing final block of elements on the list
part
¶The first part in the linked-list
size
¶The size of each element on the list
nalloc
¶The number of allocated elements on the list
ngx_list_part_t
¶A structure containing the details of a block of elements in a c:type:ngx_list_t linked-list.
elts
¶A pointer to the first element on this block
nelts
¶The number of continuous elements stored in this block
next
¶A pointer to the next part of this list
ngx_buf_t
¶pos
¶Current position in a memory buffer window
last
¶End of a memory buffer window
file_pos
¶Current position of a file buffer
file_last
¶End of a file buffer
start
¶Beginning of a memory buffer
end
¶End of a memory buffer
tag
¶A pointer to tag buffers with
file
¶File pointer for a file buffer
temporary:1
¶A writeable in-memory buffer
memory:1
¶A read-only in-memory buffer
mmap:1
¶A mmap()ed read-only buffer
recycled:1
¶Buffer is reused after release
in_file:1
¶Buffer is a file buffer
flush:1
¶All buffered data has been flushed
last_buf:1
¶Buffer is the last in a stream of data
last_in_chain:1
¶Buffer is the last in a buffer chain
temp_file:1
¶Buffer is a temporary file
ngx_bufs_t
¶A structure to contain details about a required chain of buffers. Used by ngx_create_chain_of_bufs()
size
¶The size of each buffer in the chain
ngx_alloc
(size_t size, ngx_log_t *log)¶A wrapper for malloc with error handling. Allocates memory of a given size and returns a pointer to that memory. Requires a pointer to a log file object for the error handling. Fires an emergency level error upon failure.
Parameters: |
|
---|---|
Returns: | A pointer to the allocated memory or |
ngx_calloc
(size_t size, ngx_log_t *log)¶A wrapper for ngx_alloc()
which additionally sets every byte allocated to 0
.
Parameters: |
|
---|---|
Returns: | A pointer to the allocated memory or |
ngx_create_pool
(size_t size, ngx_log_t *log)¶Creates a pool of memory of allocated memory which can be quickly freed and reused.
The macro NGX_DEFAULT_POOL_SIZE
is recommended for use in the size variable which amounts to 16KB
Parameters: |
|
---|---|
Returns: | A pointer to the newly created memory pool or |
ngx_destroy_pool
(ngx_pool_t *pool)¶Destroys a pool, freeing all allocations associated with it.
Parameters: |
|
---|
ngx_reset_pool
(ngx_pool_t *pool)¶Resets a pool by marking all pages as free, additionally freeing any large allocations within it.
Parameters: |
|
---|
ngx_pnalloc
(ngx_pool_t *pool, size_t size)¶Allocates a block of memory from a pool.
Note
If the requested size is greater than NGX_MAX_ALLOC_FROM_POOL
(system page size - 1) it will be allocated separately as a large allocation and won’t be freed until explicitly freed with ngx_pfree()
the whole pool is reset (ngx_reset_pool()
) or destroyed (ngx_destroy_pool()
).
Parameters: |
|
---|---|
Returns: | A pointer to the memory requested or |
ngx_palloc
(ngx_pool_t *pool, size_t size)¶Similar to ngx_pnalloc()
but allocates a block of memory from the pool aligned to NGX_ALIGNMENT
Parameters: |
|
---|---|
Returns: | A pointer to the memory requested or |
ngx_pcalloc
(ngx_pool_t *pool, size_t size)¶A wrapper for ngx_palloc()
which also sets every byte of the allocation to 0
Parameters: |
|
---|---|
Returns: | A pointer to the memory requested or |
ngx_pfree
(ngx_pool_t *pool, void *p)¶Frees large allocations
Parameters: |
|
---|---|
Returns: |
|
ngx_pool_cleanup_add
(ngx_pool_t *p, size_t size)¶A wrapper for ngx_palloc()
which returns a structure the user can add a cleanup handler to
Parameters: |
|
---|---|
Returns: | A pointer to a structure containing allocation and a variable to set as the cleanup callback |
An NGINX array is an efficient way of maintaining a continuous block of memory for a small number of elements. It is particularly efficient if the size of the arry is not required to change often.
ngx_array_create
(ngx_pool_t *p, ngx_uint_t n, size_t size)¶Creates an array from a memory pool and allocates an initial continuous block of memory for its elements
Parameters: |
|
---|---|
Returns: | A newly created array |
ngx_array_destroy
(ngx_array_t *a)¶Destroys a array, freeing allocations back to the pool
Parameters: |
|
---|
ngx_array_push
(ngx_array_t *a)¶Creates a new element on the array and returns a pointer to this element
Note
this may cause a re-allocation of the array depending on the current state of the pool which in-turn could cause a small performance hit
Parameters: |
|
---|---|
Returns: | a pointer to the new element on the array |
ngx_array_push_n
(ngx_array_t *a, ngx_uint_t n)¶Creates a number of new elements on the array and returns a pointer to the first of these elements
Note
this may cause a re-allocation of the array depending on the current state of the pool which in-turn could cause a small performance hit
Parameters: |
|
---|---|
Returns: | a pointer to the first new element |
A linked-list in NGINX is used to maintain a growing list of items which can be iterated through. NGINX stores these in blocks called ‘parts’, each part can contain several elements on the list.
ngx_list_create
(ngx_pool_t *pool, ngx_uint_t n, size_t size)¶Creates a linked-list from a memory pool and allocates an initial block of memory for the list
Parameters: |
|
---|---|
Returns: | A newly allocated linked-list |
ngx_list_push
(ngx_list_t *list)¶Allocates and adds a new element onto the linked-list in the memory pool
Parameters: |
|
---|---|
Returns: | The newly allocated element on the list |
ngx_alloc_buf
(ngx_pool_t *pool)¶A macro which creates a ngx_buf_t
structure in a memory pool
Parameters: |
|
---|---|
Returns: | A pointer to the buffer |
ngx_calloc_buf
(ngx_pool_t *pool)¶A macro which creates a cleared ngx_buf_t
structure in a memory pool
Parameters: |
|
---|---|
Returns: | A pointer to the buffer |
ngx_create_temp_buf
(ngx_pool_t *pool, size_t size)¶Creates a temporary buffer of a given size
Parameters: |
|
---|---|
Returns: | A newly created temporary buffer |
ngx_alloc_chain_link
(ngx_pool_t *pool)¶Allocates memory for a link in the chain from a given memory pool. It will automatically link this to other chains in the pool
Parameters: |
|
---|---|
Returns: | The new chain link |
ngx_create_chain_of_bufs
(ngx_pool_t *pool, ngx_bufs_t *bufs)¶Allocates a chain of links and the buffers inside of them from a given memory pool
Parameters: |
|
---|---|
Returns: | The first link in the new chain |
ngx_chain_get_free_buf
(ngx_pool_t *p, ngx_chain_t **free)¶Finds the first free buffer link in the chain and returns it. If there are no free links it allocates one and returns it
Parameters: |
|
---|---|
Returns: | The first free chain link |
ngx_free_chain
(ngx_pool_t *pool, ngx_chain_t *cl)¶Releases a link in the chain
Parameters: |
|
---|
ngx_chain_add_copy
(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in)¶Copies one chain to the end of another chain without copying the buffered contents. Essentially adding links into pre-existing chain.
Parameters: |
|
---|---|
Returns: |
|
ngx_chain_update_chains
(ngx_chain_t **free, ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag)¶Moves the buffers from the out
to busy
and processed chains in busy
with tag
to the free
chain.
Parameters: |
|
---|