mempool.h revision 17654607d6adbe64923f023a7120627544c540c8
#ifndef MEMPOOL_H
#define MEMPOOL_H
#include "macros.h"
/* When DEBUG is enabled, Dovecot warns whenever a memory pool is grown.
This is done so that the initial pool size could be set large enough so that
it wouldn't grow in normal use. For some memory pools it's too difficult
to calculate a good initial size, so this prefix should be used with those
pools to disable the warning. */
#define MEMPOOL_GROWING "GROWING-"
/* Memory allocated and reallocated (the new data in it) in pools is always
zeroed, it will cost only a few CPU cycles and may well save some debug
time. */
struct pool_vfuncs {
/* memory in old_size..new_size will be zeroed */
/* Frees all the memory in pool. NOTE: system_pool doesn't support
this and crashes if it's used */
/* Returns the maximum amount of bytes that can be allocated with
minimal trouble. If there's no such concept, always returns 0. */
};
struct pool {
const struct pool_vfuncs *v;
unsigned int alloconly_pool:1;
unsigned int datastack_pool:1;
};
/* system_pool uses calloc() + realloc() + free() */
extern pool_t system_pool;
extern struct pool static_system_pool;
/* memory allocated from data_stack is valid only until next t_pop() call.
No checks are performed. */
extern pool_t unsafe_data_stack_pool;
/* Create a new alloc-only pool. Note that `size' specifies the initial
malloc()ed block size, part of it is used internally. */
/* When allocating memory from returned pool, the data stack frame must be
the same as it was when calling this function. pool_unref() also checks
that the stack frame is the same. This should make it quite safe to use. */
pool_t pool_datastack_create(void);
/* Similar to nearest_power(), but try not to exceed buffer's easy
allocation size. If you don't have any explicit minimum size, use
old_size + 1. */
static inline void * ATTR_MALLOC ATTR_RETURNS_NONNULL
{
}
static inline void * ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
{
}
/* Free the memory. Currently it also sets memory to NULL, but that shouldn't
be relied on as it's only an extra safety check. It might as well be later
changed to some invalid pointer causing a segfault, or removed completely
in some "optimization".. */
STMT_START { \
} STMT_END
/* A macro that's guaranteed to set mem = NULL. */
{
}
{
}
{
}
{
}
{
}
{
}
/* These functions are only for pools created with pool_alloconly_create(): */
/* Returns how much memory has been allocated from this pool. */
/* Returns how much system memory has been allocated for this pool. */
#endif