mempool.h revision ad0ef8f436c41037e9f1d70286f7054e400fad92
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen/* #define POOL_CHECK_LEAKS */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Memory allocated and reallocated (the new data in it) in pools is always
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen zeroed, it will cost only a few CPU cycles and may well save some debug
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* memory in old_size..new_size will be zeroed */
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen /* Frees all the memory in pool. NOTE: system_pool doesn't support
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen this and crashes if it's used */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* system_pool uses calloc() + realloc() + free() */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* memory allocated from data_stack is valid only until next t_pop() call. */
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen/* Create a new alloc-only pool. Note that `size' specifies the initial
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen malloc()ed block size, part of it is used internally. */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenpool_t pool_alloconly_create(const char *name, size_t size);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Pools should be used through these macros: */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen#define pool_get_name(pool) (pool)->get_name(pool)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#define p_malloc(pool, size) (pool)->malloc(pool, size)
14175321ddb88619015866978c05a27786ca4814Timo Sirainen#define p_realloc(pool, mem, old_size, new_size) \
14175321ddb88619015866978c05a27786ca4814Timo Sirainen (pool)->realloc(pool, mem, old_size, new_size)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen#define p_free(pool, mem) (pool)->free(pool, mem)
1060afdc2fcdf647dbb3bc11647401f1b44a3a8aTimo Sirainen/* Extra macros to make life easier: */
8edc373587d75f8040e3c4416e50638aa2a32188Timo Sirainen ((type *) p_malloc(pool, sizeof(type) * (count)))
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen/* p_free_clean() should be used when pool is being destroyed, so freeing
c9bf63e9094761767a63ac6b189bcf60bcffdc44Timo Sirainen memory isn't needed for anything else than detecting memory leaks. */