mempool.h revision dd0fd94add215d793a6869215c0509308b94c877
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Memory allocated and reallocated (the new data in it) in pools is always
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen zeroed, it will cost only a few CPU cycles and may well save some debug
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen /* memory in old_size..new_size will be zeroed */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Frees all the memory in pool. NOTE: system_pool doesn't support
8363f50d7b5d605912e55c34f7f28e9f4ce01341Timo Sirainen this and crashes if it's used */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Returns the maximum amount of bytes that can be allocated with
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen minimal trouble. If there's no such concept, always returns 0. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen size_t (*get_max_easy_alloc_size)(pool_t pool);
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen/* system_pool uses calloc() + realloc() + free() */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen/* memory allocated from data_stack is valid only until next t_pop() call.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen No checks are performed. */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen/* Create a new alloc-only pool. Note that `size' specifies the initial
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainen malloc()ed block size, part of it is used internally. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenpool_t pool_alloconly_create(const char *name, size_t size);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* When allocating memory from returned pool, the data stack frame must be
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen the same as it was when calling this function. pool_unref() also checks
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen that the stack frame is the same. This should make it quite safe to use. */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen/* Pools should be used through these macros: */
98922c5675bbbfadc84d58768bef867fe82256c2Timo Sirainen#define pool_get_name(pool) (pool)->get_name(pool)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ((type *) p_malloc(pool, sizeof(type) * (count)))
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define p_malloc(pool, size) (pool)->malloc(pool, size)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define p_realloc(pool, mem, old_size, new_size) \
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen (pool)->realloc(pool, mem, old_size, new_size)