GNU libmicrohttpd 1.0.1
|
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for each request More...
#include "mhd_options.h"
Go to the source code of this file.
Functions | |
void | MHD_init_mem_pools_ (void) |
struct MemoryPool * | MHD_pool_create (size_t max) |
void | MHD_pool_destroy (struct MemoryPool *pool) |
void * | MHD_pool_allocate (struct MemoryPool *pool, size_t size, bool from_end) |
bool | MHD_pool_is_resizable_inplace (struct MemoryPool *pool, void *block, size_t block_size) |
void * | MHD_pool_try_alloc (struct MemoryPool *pool, size_t size, size_t *required_bytes) |
void * | MHD_pool_reallocate (struct MemoryPool *pool, void *old, size_t old_size, size_t new_size) |
size_t | MHD_pool_get_free (struct MemoryPool *pool) |
void | MHD_pool_deallocate (struct MemoryPool *pool, void *block, size_t block_size) |
void * | MHD_pool_reset (struct MemoryPool *pool, void *keep, size_t copy_bytes, size_t new_size) |
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for each request
Definition in file memorypool.h.
void MHD_init_mem_pools_ | ( | void | ) |
Initialize values for memory pools
Initialise values for memory pools
Definition at line 209 of file memorypool.c.
References ALIGN_SIZE, mhd_assert, MHD_DEF_PAGE_SIZE_, and MHD_sys_page_size_.
Referenced by MHD_init().
void * MHD_pool_allocate | ( | struct MemoryPool * | pool, |
size_t | size, | ||
bool | from_end | ||
) |
Allocate size bytes from the pool.
pool | memory pool to use for the operation |
size | number of bytes to allocate |
from_end | allocate from end of pool (set to 'true'); use this for small, persistent allocations that will never be reallocated |
Definition at line 399 of file memorypool.c.
References _MHD_UNPOISON_MEMORY, mhd_assert, NULL, ROUND_TO_ALIGN, and ROUND_TO_ALIGN_PLUS_RED_ZONE.
struct MemoryPool * MHD_pool_create | ( | size_t | max | ) |
Create a memory pool.
max | maximum size of the pool |
Definition at line 102 of file memorypool.c.
References _MHD_POISON_MEMORY, ALIGN_SIZE, MAP_FAILED, mhd_assert, MHD_sys_page_size_, NULL, and ROUND_TO_ALIGN.
Referenced by internal_add_connection(), and new_connection_process_().
void MHD_pool_deallocate | ( | struct MemoryPool * | pool, |
void * | block, | ||
size_t | block_size | ||
) |
Deallocate a block of memory obtained from the pool.
If the given block is not the most recently (re)allocated block, the memory of the this block allocation may be not released until the pool is destroyed or reset.
pool | memory pool to use for the operation |
block | the allocated block, the NULL is tolerated |
block_size | the size of the allocated block |
Definition at line 625 of file memorypool.c.
References _MHD_POISON_MEMORY, _MHD_RED_ZONE_SIZE, mhd_assert, mp_ptr_diff_, mp_ptr_le_, NULL, ROUND_TO_ALIGN, and ROUND_TO_ALIGN_PLUS_RED_ZONE.
Referenced by connection_shrink_read_buffer(), and transmit_error_response_len().
void MHD_pool_destroy | ( | struct MemoryPool * | pool | ) |
Destroy a memory pool.
pool | memory pool to destroy |
Definition at line 157 of file memorypool.c.
References _MHD_UNPOISON_MEMORY, mhd_assert, NULL, and ROUND_TO_ALIGN.
Referenced by internal_add_connection(), MHD_cleanup_connections(), MHD_connection_cleanup_(), MHD_connection_close_(), MHD_request_handle_idle_(), and new_connection_process_().
size_t MHD_pool_get_free | ( | struct MemoryPool * | pool | ) |
Check how much memory is left in the pool
pool | pool to check |
Definition at line 185 of file memorypool.c.
References _MHD_RED_ZONE_SIZE, mhd_assert, and ROUND_TO_ALIGN.
Referenced by connection_maximize_write_buffer(), try_grow_read_buffer(), and try_ready_chunked_body().
bool MHD_pool_is_resizable_inplace | ( | struct MemoryPool * | pool, |
void * | block, | ||
size_t | block_size | ||
) |
Checks whether allocated block is re-sizable in-place. If block is not re-sizable in-place, it still could be shrunk, but freed memory will not be re-used until reset of the pool.
pool | the memory pool to use |
block | the pointer to the allocated block to check |
block_size | the size of the allocated block |
Definition at line 440 of file memorypool.c.
References mhd_assert, mp_ptr_diff_, mp_ptr_le_, NULL, and ROUND_TO_ALIGN_PLUS_RED_ZONE.
Referenced by connection_maximize_write_buffer(), connection_shrink_read_buffer(), MHD_connection_alloc_memory_(), try_grow_read_buffer(), and try_ready_chunked_body().
void * MHD_pool_reallocate | ( | struct MemoryPool * | pool, |
void * | old, | ||
size_t | old_size, | ||
size_t | new_size | ||
) |
Reallocate a block of memory obtained from the pool. This is particularly efficient when growing or shrinking the block that was last (re)allocated. If the given block is not the most recently (re)allocated block, the memory of the previous allocation may be not released until the pool is destroyed or reset.
pool | memory pool to use for the operation |
old | the existing block |
old_size | the size of the existing block |
new_size | the new size of the block |
Reallocate a block of memory obtained from the pool. This is particularly efficient when growing or shrinking the block that was last (re)allocated. If the given block is not the most recently (re)allocated block, the memory of the previous allocation may be leaked until the pool is destroyed (and copying the data maybe required).
pool | memory pool to use for the operation |
old | the existing block |
old_size | the size of the existing block |
new_size | the new size of the block |
Definition at line 248 of file memorypool.c.
References _MHD_POISON_MEMORY, _MHD_RED_ZONE_SIZE, _MHD_UNPOISON_MEMORY, mhd_assert, mp_ptr_diff_, mp_ptr_le_, NULL, ROUND_TO_ALIGN, and ROUND_TO_ALIGN_PLUS_RED_ZONE.
Referenced by check_write_done(), connection_maximize_write_buffer(), connection_shrink_read_buffer(), MHD_connection_alloc_memory_(), MHD_connection_handle_read(), MHD_request_handle_read_(), process_broken_line(), try_grow_read_buffer(), try_grow_read_buffer(), and try_ready_chunked_body().
void * MHD_pool_reset | ( | struct MemoryPool * | pool, |
void * | keep, | ||
size_t | copy_bytes, | ||
size_t | new_size | ||
) |
Clear all entries from the memory pool except for keep of the given copy_bytes. The pointer returned should be a buffer of new_size where the first copy_bytes are from keep.
pool | memory pool to use for the operation |
keep | pointer to the entry to keep (maybe NULL) |
copy_bytes | how many bytes need to be kept at this address |
new_size | how many bytes should the allocation we return have? (should be larger or equal to copy_bytes) |
Clear all entries from the memory pool except for keep of the given size. The pointer returned should be a buffer of new_size where the first copy_bytes are from keep.
pool | memory pool to use for the operation |
keep | pointer to the entry to keep (maybe NULL) |
copy_bytes | how many bytes need to be kept at this address |
new_size | how many bytes should the allocation we return have? (should be larger or equal to copy_bytes) |
Size of area to zero-out
Definition at line 314 of file memorypool.c.
References _MHD_POISON_MEMORY, _MHD_UNPOISON_MEMORY, mhd_assert, MHD_sys_page_size_, mp_ptr_diff_, mp_ptr_le_, NULL, ROUND_TO_ALIGN, and ROUND_TO_ALIGN_PLUS_RED_ZONE.
Referenced by connection_reset(), MHD_request_handle_idle_(), and transmit_error_response_len().
void * MHD_pool_try_alloc | ( | struct MemoryPool * | pool, |
size_t | size, | ||
size_t * | required_bytes | ||
) |
Try to allocate size bytes memory area from the pool.
If allocation fails, required_bytes is updated with size required to be freed in the pool from rellocatable area to allocate requested number of bytes. Allocated memory area is always not rellocatable ("from end").
pool | memory pool to use for the operation | |
size | the size of memory in bytes to allocate | |
[out] | required_bytes | the pointer to variable to be updated with the size of the required additional free memory area, set to 0 if function succeeds. Cannot be NULL. |
Definition at line 481 of file memorypool.c.
References _MHD_UNPOISON_MEMORY, mhd_assert, NULL, ROUND_TO_ALIGN, ROUND_TO_ALIGN_PLUS_RED_ZONE, and SIZE_MAX.
Referenced by MHD_connection_alloc_memory_().