Memory allocation library similar to malloc, focused on low memory overhead,
using a given memory block (e.g. an arena).
#include <mini_malloc.h>
#define BLOCKSIZE 1024
int main(void) {
void* block = malloc(BLOCKSIZE);
struct mini_malloc* mm = init_mini_malloc(block, BLOCKSIZE);
void* foo = mm_alloc(mm, 32);
mm_free(mm, foo);
free(block);
return 0;
}The allocator is implemented to have low memory overhead (8 bytes per allocated
block, 272 bytes static in addition). Allocations use one of 60 fixed memory
sizes, divisible by 8 and increasing in size by a factor of pow(2.0, 0.25).
Freed nodes are reinserted into the free memory pool, adjacent free nodes are
joined. Allocation should be quite efficient, though no optimizations regarding
cache locality or multi-threading were considered.
- Each instance can only use a single, non-growing memory block.
- Multi-threading is not considered and must be handled by the library user.
- A
realloc()function is not provided.
This repo is released under the BSD 3-Clause License. See LICENSE file for details.