A lightweight C++ memory pool allocator.
alloc is a simple, byte-oriented bump allocator that manages a preallocated block of contiguous memory.
- Contiguous memory pool
- Bump allocation strategy
- Allocation bounds checking
- Memory pool reset and reuse
- Automatic memory cleanup
- Lightweight C++ implementation
alloc/
├── include/
│ └── alloc/
│ └── allocator.hpp
├── src/
│ └── allocator.cpp
├── examples/
│ └── basic.cpp
├── tests/
│ └── allocator_test.cpp
├── CMakeLists.txt
└── README.md
- C++17 compatible compiler
- CMake 3.20 or newer
git clone YOUR_REPOSITORY_URL
cd alloc
cmake -S . -B build
cmake --build build#include <iostream>
#include "alloc/allocator.hpp"
int main()
{
mem_pool pool(1024);
void* memory = pool.allocate(64);
if (memory == nullptr)
{
std::cout << "Allocation failed\n";
return 1;
}
std::cout << "Allocation successful\n";
pool.reset();
std::cout << "Memory pool reset\n";
}| Method | Description |
|---|---|
mem_pool(size_t) |
Constructs a memory pool with the specified capacity |
allocate(size_t) |
Allocates memory from the pool |
reset() |
Resets pool usage to zero, allowing memory to be reused |
alloc uses a bump allocation strategy.
A fixed block of contiguous memory is allocated when a mem_pool object is constructed. Subsequent allocation requests receive portions of that block.
The allocator tracks used capacity and rejects requests that exceed the remaining space.
The reset() method resets the allocation counter to zero, allowing the entire pool to be reused without allocating another block of memory.
Memory is released automatically when the pool is destroyed.
- No individual deallocation.
- No automatic memory resizing.
- No general-purpose alignment guarantee for arbitrary allocation offsets.
- The allocator is not thread-safe.
This project is licensed under the MIT License.
See LICENSE for details.