Part of Project_zero.
A header-only static library providing several custom memory allocators that are fully compatible with the C++ standard allocator interface (std::allocator_traits). They can be plugged directly into any STL container or the custom ADT containers.
Memory resources (low-level)
Pool_resource— fixed-size block pool; allocates from a pre-allocated slab, recycles freed blocks via a free-listMonotonic_resource— bump-pointer allocator; extremely fast allocation, no individual deallocation (free all at once)Stack_resource— LIFO stack-based resource; deallocations must happen in reverse order
STL-compatible allocators (high-level wrappers)
Pool_allocator<T>— wrapsPool_resourceMonotonic_allocator<T>— wrapsMonotonic_resourceStack_allocator<T>— wrapsStack_resourceSegregated_allocator<T>— segregated free-list; routes allocations to size-class buckets for low fragmentation
Diagnostics
Debug_allocator<T>— wraps any allocator; tracks total allocations, deallocations, and currently live bytes; detects leaks at destruction
1. Include the header
#include "Allocator.h"Add the Allocator/ folder to your include path if needed.
2. Link the static library
In Visual Studio:
- Linker → Input → Additional Dependencies → add
Allocator.lib - Linker → General → Additional Library Directories → add the path to
x64/Release/
#include "Allocator.h"
#include <vector>
#include <iostream>
int main() {
// Pool allocator with a std::vector
Pool_allocator<int> pool_alloc;
std::vector<int, Pool_allocator<int>> vec(pool_alloc);
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
// Debug allocator wrapping the default allocator
Debug_allocator<int> dbg;
std::vector<int, Debug_allocator<int>> dbg_vec(dbg);
dbg_vec.push_back(10);
dbg_vec.push_back(20);
// On destruction, Debug_allocator will report any leaks
// Monotonic resource for short-lived scratch allocations
Monotonic_resource mono(1024); // 1 KB buffer
Monotonic_allocator<double> mono_alloc(&mono);
}Monotonic_resourcedoes not support individualdeallocatecalls — memory is released all at once when the resource goes out of scope. It is best used for temporary/arena-style allocations.Debug_allocatorhas a small runtime overhead and is intended for debug builds only.- All allocators satisfy the
std::allocator_traitsrequirements and work with any standard or custom container.