Dynamic memory allocator inspired by Doug Lea.
More...
|
#define | MP_USE_SYSTEM_MEMSET /* use system memset from string.h */ |
|
#define | MP_USE_SYSTEM_MEMCPY /* use system memcpy from string.h */ |
|
#define | MP_memset(b, c, len) ua_memset(b, c, len) |
|
#define | MP_memcpy(dest, src, n) ua_memcpy(dest, src, n) |
|
#define | MP_UNUSED(x) (void)x |
|
#define | SIZE_T_ZERO ((size_t)0) |
|
#define | SIZE_T_ONE ((size_t)1) |
|
#define | SIZE_T_TWO ((size_t)2) |
|
#define | NUM_SIZE_T_ENTRIES 4 |
|
#define | MIN_CHUNK_SIZE (sizeof(size_t) * NUM_SIZE_T_ENTRIES) |
|
#define | CHUNK_STEPS MIN_CHUNK_SIZE |
|
#define | NUM_BINS 32 |
|
#define | LAST_BIN 31 |
|
#define | CHUNK_SIZE_CLEAR_MASK ((size_t)7) |
|
#define | CHUNK_SIZE_MASK ((size_t)~7) |
|
#define | USED_BIT SIZE_T_ONE |
|
#define | CLEAN_SIZE(x) ((x) & CHUNK_SIZE_MASK) |
|
#define | INDEX2SIZE(x) (MIN_CHUNK_SIZE+(x)*CHUNK_STEPS) |
|
#define | SIZE2INDEX(x) ((((x)-MIN_CHUNK_SIZE)/CHUNK_STEPS) > LAST_BIN ? LAST_BIN : (((x)-MIN_CHUNK_SIZE)/CHUNK_STEPS)) |
|
#define | MP_STATUS 0 /* HEADER */ |
|
#define | MP_SIZE 0 /* HEADER */ |
|
#define | MP_PREV 1 /* USED for data when MP_STATUS != FREE */ |
|
#define | MP_NEXT 2 /* USED for data when MP_STATUS != FREE */ |
|
#define | MP_NODE_HEADER sizeof(size_t) * 1 /* only size field in header */ |
|
#define | MP_NODE_OVERHEAD sizeof(size_t) * 2 /* NODEHEADER+size at the end */ |
|
#define | MEMTRACE_BUFFER_SIZE sizeof(struct memtrace_status) + (sizeof(int) + sizeof(struct logentry)) * MEMORY_TRACE_LOG_SIZE |
|
|
int | mempool_init (struct mempool *pool, unsigned char *data, size_t size) |
| Initializes a memory pool. More...
|
|
void | mempool_cleanup (struct mempool *pool) |
| Cleanup a memory pool. More...
|
|
void * | mempool_alloc (struct mempool *pool, size_t size) |
| Allocates memory in the given mempool. More...
|
|
void * | mempool_realloc (struct mempool *pool, void *ptr, size_t size) |
|
void | mempool_free (struct mempool *pool, void *ptr) |
| Frees the given memory block, that was allocated by MP_Alloc before. More...
|
|
void | mempool_set_alloc_break (int allocbreak) |
|
void | mempool_add_alloc_break (int allocbreak) |
| Allow further allocbreak allocations, then fail. More...
|
|
int | mempool_alloc_inc (void) |
| Increment allocation counter.
|
|
void | log_init (void *tracemem) |
|
void | log_create (void *tracemem) |
|
void * | log_mem (void) |
|
int | log_stack_push (int idx) |
|
int | log_stack_pop (void) |
|
void | log_add (struct malloc_chunk *chunk, const char *file, int line) |
|
void | log_remove (struct malloc_chunk *chunk) |
|
void | log_dump (void) |
|
Dynamic memory allocator inspired by Doug Lea.
The mempool is initialized with an amount of memory, then mempool_alloc can be used to allocate chunks of dynamic size from this memory.
void mempool_add_alloc_break |
( |
int |
allocbreak | ) |
|
Allow further allocbreak
allocations, then fail.
To disable non-triggered allocbreak call: mempool_set_alloc_break(0)
void* mempool_alloc |
( |
struct mempool * |
pool, |
|
|
size_t |
size |
|
) |
| |
Allocates memory in the given mempool.
- Parameters
-
pool | Pointer to pool to use. |
size | Number of bytes to allocate. |
- Returns
- Pointer to new memory or NULL if allocation fails.
void mempool_cleanup |
( |
struct mempool * |
pool | ) |
|
Cleanup a memory pool.
- Parameters
-
pool | Pointer to pool which should be initialized. |
void mempool_free |
( |
struct mempool * |
pool, |
|
|
void * |
ptr |
|
) |
| |
Frees the given memory block, that was allocated by MP_Alloc before.
Only pass valid pointers, otherwise the function my crash.
- Parameters
-
pool | Pointer to pool to use. |
ptr | Pointer to dat to fre. |
int mempool_init |
( |
struct mempool * |
pool, |
|
|
unsigned char * |
data, |
|
|
size_t |
size |
|
) |
| |
Initializes a memory pool.
- Parameters
-
pool | Pointer to pool which should be initialized. |
data | Pointer to memory which should be managed by the pool; data must be aligned to pointer size. |
size | Size of the memory. |