GNU libmicrohttpd  0.9.72
memorypool.c File Reference

memory pool More...

#include "memorypool.h"
Include dependency graph for memorypool.c:

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)   ((n + (ALIGN_SIZE - 1)) & (~(ALIGN_SIZE - 1)))
 

Functions

_MHD_EXTERN void MHD_free (void *ptr)
 
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, int 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)
 

Detailed Description

memory pool

Author
Christian Grothoff

Definition in file memorypool.c.

Macro Definition Documentation

◆ ALIGN_SIZE

#define ALIGN_SIZE   (2 * sizeof(void*))

Align to 2x word size (as GNU libc does).

Definition at line 38 of file memorypool.c.

◆ MAP_FAILED

#define MAP_FAILED   ((void*) -1)

Definition at line 32 of file memorypool.c.

◆ ROUND_TO_ALIGN

#define ROUND_TO_ALIGN (   n)    ((n + (ALIGN_SIZE - 1)) & (~(ALIGN_SIZE - 1)))

Round up 'n' to a multiple of ALIGN_SIZE.

Definition at line 43 of file memorypool.c.

Function Documentation

◆ MHD_free()

_MHD_EXTERN void MHD_free ( void *  ptr)

Free the memory given by ptr. Calls "free(ptr)". This function should be used to free the username returned by MHD_digest_auth_get_username().

Note
Since v0.9.56
Parameters
ptrpointer to free.

Definition at line 89 of file memorypool.c.

◆ MHD_pool_allocate()

void* MHD_pool_allocate ( struct MemoryPool *  pool,
size_t  size,
int  from_end 
)

Allocate size bytes from the pool.

Parameters
poolmemory pool to use for the operation
sizenumber of bytes to allocate
from_endallocate from end of pool (set to MHD_YES); use this for small, persistent allocations that will never be reallocated
Returns
NULL if the pool cannot support size more bytes

Definition at line 203 of file memorypool.c.

References MHD_YES, NULL, and ROUND_TO_ALIGN.

Referenced by build_header_response(), parse_cookie_header(), and try_ready_chunked_body().

Here is the caller graph for this function:

◆ MHD_pool_create()

struct MemoryPool* MHD_pool_create ( size_t  max)

Create a memory pool.

Parameters
maxmaximum size of the pool
Returns
NULL on error

Definition at line 102 of file memorypool.c.

References MAP_FAILED, and NULL.

◆ MHD_pool_destroy()

void MHD_pool_destroy ( struct MemoryPool *  pool)

Destroy a memory pool.

Parameters
poolmemory pool to destroy

Definition at line 157 of file memorypool.c.

References NULL.

Referenced by internal_run_from_select(), MHD_connection_cleanup_(), and MHD_request_handle_idle_().

Here is the caller graph for this function:

◆ MHD_pool_get_free()

size_t MHD_pool_get_free ( struct MemoryPool *  pool)

Check how much memory is left in the pool

Parameters
poolpool to check
Returns
number of bytes still available in pool

Definition at line 185 of file memorypool.c.

Referenced by build_header_response().

Here is the caller graph for this function:

◆ MHD_pool_reallocate()

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 (and copying the data maybe required).

Parameters
poolmemory pool to use for the operation
oldthe existing block
old_sizethe size of the existing block
new_sizethe new size of the block
Returns
new address of the block, or NULL if the pool cannot support new_size bytes (old continues to be valid for old_size)

Definition at line 248 of file memorypool.c.

References NULL, and ROUND_TO_ALIGN.

Referenced by build_header_response(), check_write_done(), MHD_connection_handle_read(), MHD_request_handle_read_(), process_broken_line(), transmit_error_response(), and try_grow_read_buffer().

Here is the caller graph for this function:

◆ MHD_pool_reset()

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.

Parameters
poolmemory pool to use for the operation
keeppointer to the entry to keep (maybe NULL)
copy_byteshow many bytes need to be kept at this address
new_sizehow many bytes should the allocation we return have? (should be larger or equal to copy_bytes)
Returns
addr new address of keep (if it had to change)

Definition at line 314 of file memorypool.c.

References NULL, and ROUND_TO_ALIGN.

Referenced by MHD_request_handle_idle_().

Here is the caller graph for this function: