mempool.h revision c71a9c4d81b80083c13f908162515142b951ecf4
#ifndef __MEMPOOL_H
#define __MEMPOOL_H
#include "macros.h"
/* 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 {
/* 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 */
unsigned int alloconly_pool:1;
unsigned int datastack_pool:1;
};
/* system_pool uses calloc() + realloc() + free() */
extern pool_t 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);
/* Pools should be used through these macros: */
#define pool_unref(pool) \
STMT_START { \
} STMT_END
STMT_START { \
} STMT_END
#endif