Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Thread-Local Memory Pool Allocator

A C++20 memory allocator focused on predictable latency for performance-critical, multi-threaded systems. It provides per-thread pools and fast fixed-size allocations, plus a linear arena for short-lived allocations. It integrates with the C++ standard allocator interface for drop-in use with STL containers.

Features

  • Thread-local pools to avoid cross-thread contention.
  • Slab allocator with fixed-size classes for fast allocate/free.
  • Linear (bump) allocator for bulk temporary allocations.
  • STL-compatible std::allocator-style interface.
  • Cache-line alignment options where appropriate.

Design Overview

  • Each thread owns its pool; allocations never touch the global heap.
  • Small allocations are routed to size-class slabs.
  • Short-lived allocations can use a linear arena and be reset in O(1).

Usage

Basic Pool Allocation

#include "memory_pool.hpp"

auto& pool = hft::get_thread_pool();
void* ptr = pool.allocate(256);

int* data = static_cast<int*>(ptr);
data[0] = 42;

pool.deallocate(ptr, 256);

STL Containers

#include "stl_allocator.hpp"

std::vector<int, hft::FastPoolAllocator<int>> vec;
vec.push_back(1);

Linear Allocator

#include "memory_pool.hpp"

hft::LinearAllocator arena(1024 * 1024);
void* p1 = arena.allocate(128);
void* p2 = arena.allocate(256);

arena.reset();

Building

Make

make all
make test
make bench
make run
make clean

CMake

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

Requirements

  • C++20 compiler (GCC 10+, Clang 12+, MSVC 2019+)
  • Recommended: -O3 -march=native -flto

References

  • Wilson et al., "The Memory Allocator Problem"
  • TCMalloc (Thread-Caching Malloc)
  • jemalloc: A Scalable Concurrent Malloc Implementation

License

MIT License. See LICENSE.

Contributing

PRs welcome. Areas of interest:

  • NUMA-aware allocation
  • Huge page support
  • Profiling hooks
  • Additional size classes

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages