Header-only C++14 memory pool library with compile-time sized blocks, O(1) allocation, and zero heap allocation.
O(1) alloc/free via embedded free list
Zero heap allocation -- all storage inline
Thread-safe via std::mutex
Header-only -- single #include
Compile-time sized -- no runtime growth
-fno-exceptions -fno-rtti compatible
Pointer validation with OwnsPointer()
Type-safe ObjectPool<T> with placement new
#include < mp/mem_pool.hpp>
// Fixed-size raw block pool
mp::FixedPool<64 , 1024 > pool; // 1024 blocks of 64 bytes
void * p = pool.Allocate(); // O(1)
pool.Free(p); // O(1)
// Type-safe object pool
struct Sensor { uint32_t id; float value; };
mp::ObjectPool<Sensor, 128 > sensors;
Sensor* s = sensors.Create(1 , 25 .5f ); // placement new
sensors.Destroy(s); // ~Sensor() + free
FixedPool<BlockSize, MaxBlocks>
Method
Description
Complexity
Allocate()
Allocate a block, nullptr if full
O(1)
Free(ptr)
Return block to pool
O(1)
OwnsPointer(ptr)
Check if pointer belongs to pool
O(1)
FreeCount()
Number of available blocks
O(1)
UsedCount()
Number of allocated blocks
O(1)
Capacity()
Total pool capacity (constexpr)
O(1)
DumpState(label)
Print pool state to stdout
O(1)
ObjectPool<T, MaxObjects>
Method
Description
Complexity
Create(args...)
Construct T in pool, nullptr if full
O(1)
Destroy(obj)
Destruct T and return to pool
O(1)
OwnsPointer(obj)
Check if pointer belongs to pool
O(1)
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DMP_BUILD_TESTS=ON -DMP_BUILD_EXAMPLES=ON
cmake --build . -j
ctest --output-on-failure
Option
Default
Description
MP_BUILD_TESTS
ON
Build test suite
MP_BUILD_EXAMPLES
ON
Build examples
CMake 3.14+
C++14 compiler (GCC 7+ / Clang 6+)
MIT License. See LICENSE .