diff -r 5dbef9e07376 -r 11dffb40cd91 ucx/mempool.h --- a/ucx/mempool.h Fri Aug 16 12:41:30 2013 +0200 +++ b/ucx/mempool.h Sat Aug 17 12:04:04 2013 +0200 @@ -59,8 +59,10 @@ typedef struct { /** List of pointers to pooled memory. */ void **data; + /** Count of pooled memory items. */ size_t ndata; + /** Memory pool size. */ size_t size; } UcxMempool; @@ -92,6 +94,19 @@ int ucx_mempool_chcap(UcxMempool *pool, size_t newcap); /** + * Changes the pool size to the next smallest multiple of 16. + * + * You may use this macro, to reduce the pool size after freeing + * many pooled memory items. + * + * @param pool the pool to clamp + * @return EXIT_SUCCESS on success or + * EXIT_FAILURE on failure + */ +#define ucx_mempool_clamp(pool) ucx_mempool_chcap(pool, \ + (pool->ndata & ~0xF)+0x10) + +/** * Allocates pooled memory. * * @param pool the memory pool @@ -112,9 +127,15 @@ * @see ucx_allocator_calloc() */ void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); + /** * Reallocates pooled memory. * + * If the memory to be reallocated is not contained by the specified pool, this + * function will possibly fail. In case the memory had to be moved to another + * location, this function will print out a message to stderr + * and exit the program with error code EXIT_FAILURE. + * * @param pool the memory pool * @param ptr a pointer to the memory that shall be reallocated * @param n the new size of the memory @@ -122,6 +143,7 @@ * @see ucx_allocator_realloc() */ void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n); + /** * Frees pooled memory. *