Skip to content

A minimal C++ memory pool allocator for fixed-size objects, featuring manual and RAII-safe allocation.

License

Notifications You must be signed in to change notification settings

aarushgoradia/memory-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MemoryPoolAllocator

A lightweight fixed-size memory pool allocator in C++ with support for placement new and RAII-safe deallocation.

This project demonstrates low-level memory management using a preallocated buffer, free list tracking, and type-safe allocation. It is suitable for scenarios where fast, repeated allocations of similarly sized objects are required.

Features

  • Fixed-size block allocation from a preallocated buffer
  • Manual and RAII-safe deallocation via PoolPointer<T>
  • Alignment-aware and type-safe
  • Minimal dependencies

Build instructions

This is a CMake based project. To build:

cmake -B build
cmake --build build

Or open the folder in an IDE like CLion or Visual Studio with CMake support

Example Usage

struct Enemy {
    int hp;
    float x, y;
    Enemy(int h, float xpos, float ypos);
    ~Enemy();
};

int main {
    size_t blockSize = sizeof(MemoryBlock) + sizeof(Enemy);
    MemoryPool pool(blockSize, 10);

    Enemy* e1 = pool.allocate<Enemy>(100, 1.0f, 2.0f);
    Enemy* e2 = pool.allocate<Enemy>(75, 3.0f, 4.0f);
    PoolPointer<Enemy> e3(pool.allocate<Enemy>(60, 5.0f, 6.0f), &pool);

    pool.deallocate(e1);
    pool.deallocate(e2);
}

License

MIT License

About

A minimal C++ memory pool allocator for fixed-size objects, featuring manual and RAII-safe allocation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published