Skip to content

thiagosteps227/memory-pool-allocator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memory Pool Allocator

A simple memory pool allocator implementation in C that provides fast, fixed-size block allocation.

Overview

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

How it works

  1. Initialization: The pool is divided into fixed-size blocks linked together
  2. Allocation: Returns the first available block from the free list
  3. Deallocation: Returns the block to the front of the free list

Usage

MemoryPool pool;
initMemoryPool(&pool);

void *block = allocateMemory(&pool);  // Allocate a block
freeMemory(&pool, block);             // Free the block

Building

make mem-allocator  # Build main program
make test          # Run tests
make clean         # Clean build files

Files

  • src/main.c - Main implementation and demo
  • tests/test_memory_pool.c - Unit tests
  • Makefile - Build configuration

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors