GNU libmicrohttpd
0.9.72
|
memory pool More...
#include "memorypool.h"
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mhd_assert.h"
Go to the source code of this file.
Macros | |
#define | MAP_FAILED ((void*) -1) |
#define | ALIGN_SIZE (2 * sizeof(void*)) |
#define | ROUND_TO_ALIGN(n) |
#define | MHD_DEF_PAGE_SIZE_ (4096) |
Functions | |
void | MHD_init_mem_pools_ (void) |
struct MemoryPool * | MHD_pool_create (size_t max) |
void | MHD_pool_destroy (struct MemoryPool *pool) |
size_t | MHD_pool_get_free (struct MemoryPool *pool) |
void * | MHD_pool_allocate (struct MemoryPool *pool, size_t size, bool from_end) |
void * | MHD_pool_reallocate (struct MemoryPool *pool, void *old, size_t old_size, size_t new_size) |
void * | MHD_pool_reset (struct MemoryPool *pool, void *keep, size_t copy_bytes, size_t new_size) |
Variables | |
static size_t | MHD_sys_page_size_ = MHD_DEF_PAGE_SIZE_ |
memory pool
Definition in file memorypool.c.
#define ALIGN_SIZE (2 * sizeof(void*)) |
Align to 2x word size (as GNU libc does).
Definition at line 60 of file memorypool.c.
#define MAP_FAILED ((void*) -1) |
Definition at line 54 of file memorypool.c.
#define MHD_DEF_PAGE_SIZE_ (4096) |
Definition at line 73 of file memorypool.c.
#define ROUND_TO_ALIGN | ( | n | ) |
Round up 'n' to a multiple of ALIGN_SIZE.
Definition at line 65 of file memorypool.c.
void MHD_init_mem_pools_ | ( | void | ) |
Initialise values for memory pools
Definition at line 85 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 265 of file memorypool.c.
References mhd_assert, NULL, and ROUND_TO_ALIGN.
struct MemoryPool* MHD_pool_create | ( | size_t | max | ) |
Create a memory pool.
max | maximum size of the pool |
Definition at line 146 of file memorypool.c.
References ALIGN_SIZE, MAP_FAILED, mhd_assert, MHD_sys_page_size_, NULL, and ROUND_TO_ALIGN.
void MHD_pool_destroy | ( | struct MemoryPool * | pool | ) |
Destroy a memory pool.
pool | memory pool to destroy |
Definition at line 214 of file memorypool.c.
References mhd_assert, and NULL.
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 245 of file memorypool.c.
References mhd_assert.
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 leaked 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 |
Definition at line 312 of file memorypool.c.
References mhd_assert, NULL, and ROUND_TO_ALIGN.
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 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 390 of file memorypool.c.
References mhd_assert, MHD_sys_page_size_, NULL, and ROUND_TO_ALIGN.
|
static |
Size of memory page
Definition at line 79 of file memorypool.c.
Referenced by MHD_init_mem_pools_(), MHD_pool_create(), and MHD_pool_reset().