GNU libmicrohttpd 0.9.5
memorypool.c File Reference

memory pool More...

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

Go to the source code of this file.

Defines

#define MAP_FAILED   ((void*)-1)
#define ALIGN_SIZE   (2 * sizeof(void*))
#define ROUND_TO_ALIGN(n)   ((n+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1)))

Functions

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, 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 size)

Detailed Description

memory pool

Author:
Christian Grothoff

Definition in file memorypool.c.


Define Documentation

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

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

Definition at line 38 of file memorypool.c.

#define MAP_FAILED   ((void*)-1)

Definition at line 32 of file memorypool.c.

Referenced by MHD_pool_create().

#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.

Referenced by MHD_pool_allocate(), MHD_pool_reallocate(), and MHD_pool_reset().


Function Documentation

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

Allocate size bytes from the pool.

Returns:
NULL if the pool cannot support size more bytes

Definition at line 134 of file memorypool.c.

References MHD_YES, NULL, and ROUND_TO_ALIGN.

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

Here is the caller graph for this function:

struct MemoryPool* MHD_pool_create ( size_t  max) [read]

Create a memory pool.

Parameters:
maxmaximum size of the pool

Definition at line 80 of file memorypool.c.

References MAP_FAILED, MHD_NO, MHD_YES, MMAP, and NULL.

Referenced by MHD_connection_get_pollfd().

Here is the caller graph for this function:

void MHD_pool_destroy ( struct MemoryPool *  pool)

Destroy a memory pool.

Definition at line 117 of file memorypool.c.

References MHD_NO, MUNMAP, and NULL.

Referenced by MHD_cleanup_connections(), and MHD_connection_handle_idle().

Here is the caller graph for this function:

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 recenlty (re)allocated block, the memory of the previous allocation may be leaked until the pool is destroyed (and copying the data maybe required).

Parameters:
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 172 of file memorypool.c.

References NULL, old, and ROUND_TO_ALIGN.

Referenced by check_write_done(), get_next_header_line(), MHD_connection_handle_read(), process_broken_line(), and try_grow_read_buffer().

Here is the caller graph for this function:

void* MHD_pool_reset ( struct MemoryPool *  pool,
void *  keep,
size_t  size 
)

Clear all entries from the memory pool except for "keep" of the given "size".

Parameters:
keeppointer to the entry to keep (maybe NULL)
sizehow many bytes need to be kept at this address
Returns:
addr new address of "keep" (if it had to change)

Definition at line 221 of file memorypool.c.

References NULL, and ROUND_TO_ALIGN.

Referenced by MHD_connection_handle_idle().

Here is the caller graph for this function: