A simple memory pool allocator implementation in C that provides fast, fixed-size block allocation.
The memory pool allocator pre-allocates a fixed-size buffer (1024 bytes) and manages it as a linked list of free blocks. This approach provides:
- Fast allocation/deallocation - O(1) operations
- No fragmentation - Fixed-size blocks
- Predictable memory usage - Pre-allocated pool
- Initialization: The pool is divided into fixed-size blocks linked together
- Allocation: Returns the first available block from the free list
- Deallocation: Returns the block to the front of the free list
MemoryPool pool;
initMemoryPool(&pool);
void *block = allocateMemory(&pool); // Allocate a block
freeMemory(&pool, block); // Free the blockmake mem-allocator # Build main program
make test # Run tests
make clean # Clean build filessrc/main.c- Main implementation and demotests/test_memory_pool.c- Unit testsMakefile- Build configuration