33![ CI] ( https://github.com/NotKeira/fast-alloc/workflows/CI/badge.svg )
44
55High-performance custom memory allocators with comprehensive benchmarks for game development and real-time applications.
6+
67## Allocators
78
89- ** Pool Allocator** : Fixed-size block allocation for homogeneous objects (particles, game entities)
10+ - ** Thread-Safe Pool Allocator** : Mutex-protected pool allocator for concurrent access
911- ** Stack Allocator** : Linear allocator with frame-based reset for temporary allocations
1012- ** Free List Allocator** : General-purpose allocator with first-fit and best-fit strategies
1113
1214## Performance
1315
14- Benchmarks on Windows (MSVC, Release build) demonstrate significant performance improvements over standard allocation:
16+ Benchmarks across multiple platforms demonstrate significant performance improvements over standard allocation:
17+
18+ ### Linux (GCC Release)
19+
20+ | Allocator | Operation | Time | vs Standard | Speedup |
21+ | ---------------------------| -----------------------------| --------| ---------------------| ------------------|
22+ | ** Pool** | Single allocation | 1.97ns | 7.07ns (new/delete) | ** 3.6x faster** |
23+ | ** Stack** | Single allocation | 2.20ns | 5.16ns (malloc) | ** 2.3x faster** |
24+ | ** Stack** | Frame pattern (1000 allocs) | 1203ns | 12715ns (malloc) | ** 10.6x faster** |
25+ | ** Free List (First-Fit)** | Single allocation | 4.99ns | 4.85ns (malloc) | ** Similar** |
26+ | ** Free List (Best-Fit)** | Single allocation | 5.80ns | 4.85ns (malloc) | ** Similar** |
27+
28+ ### macOS (Apple Clang Release)
29+
30+ | Allocator | Operation | Time | vs Standard | Speedup |
31+ | ---------------------------| -----------------------------| --------| ---------------------| -----------------|
32+ | ** Pool** | Single allocation | 4.38ns | 19.4ns (new/delete) | ** 4.4x faster** |
33+ | ** Stack** | Single allocation | 2.37ns | 16.9ns (malloc) | ** 7.1x faster** |
34+ | ** Stack** | Frame pattern (1000 allocs) | 3736ns | 20393ns (malloc) | ** 5.5x faster** |
35+ | ** Free List (First-Fit)** | Single allocation | 7.48ns | 16.5ns (malloc) | ** 2.2x faster** |
36+
37+ ### Windows (MSVC Release)
1538
16- | Allocator | Operation | Time | vs Standard | Speedup |
17- | ---------------------------| -----------------------------| -------| -----------------------| -----------------|
18- | ** Pool** | Single allocation | 4.5ns | 33ns (new/delete) | ** 7.3x faster** |
19- | ** Stack** | Single allocation | 6.7ns | 31ns (malloc/free) | ** 4.6x faster** |
20- | ** Stack** | Frame pattern (1000 allocs) | 5.8μs | 38μs (malloc pattern) | ** 6.5x faster** |
21- | ** Free List (First-Fit)** | Single allocation | 15ns | 31ns (malloc) | ** 2.1x faster** |
22- | ** Free List (Best-Fit)** | Single allocation | 16ns | 31ns (malloc) | ** 1.9x faster** |
39+ | Allocator | Operation | Time | vs Standard | Speedup |
40+ | ---------------------------| -----------------------------| --------| ---------------------| ------------------|
41+ | ** Pool** | Single allocation | 2.22ns | 36.9ns (new/delete) | ** 16.6x faster** |
42+ | ** Stack** | Single allocation | 1.26ns | 36.2ns (malloc) | ** 28.7x faster** |
43+ | ** Stack** | Frame pattern (1000 allocs) | 1269ns | 44627ns (malloc) | ** 35.2x faster** |
44+ | ** Free List (First-Fit)** | Single allocation | 5.25ns | 36.2ns (malloc) | ** 6.9x faster** |
2345
2446### Key Results
2547
26- - ** Pool Allocator** : 220M allocations/sec vs 30M with ` new/delete `
27- - ** Stack Allocator** : 152M allocations/sec vs 33M with ` malloc `
48+ - ** Pool Allocator** : Up to 500M+ allocations/sec vs 50-150M with ` new/delete `
49+ - ** Stack Allocator** : Up to 800M+ allocations/sec vs 25-200M with ` malloc `
50+ - ** Windows shows most dramatic improvements** due to Windows heap overhead
2851- ** Zero fragmentation** with Pool and Stack allocators
2952- ** Automatic coalescence** reduces fragmentation in Free List allocator
53+ - ** Thread-safe variant** available for concurrent workloads
3054
3155## Building
3256
33- Requires C++20 compiler and CMake 4.0 +.
57+ Requires C++20 compiler and CMake 3.14 +.
3458
3559### Windows (MSVC)
3660
3761``` bash
3862cmake -B build
3963cmake --build build --config Release
4064.\b uild\R elease\a lloc_benchmarks.exe
41- . \ b uild\D ebug \a lloc_tests.exe
65+ ctest --test-dir build -C Release
4266```
4367
4468### Linux/macOS
@@ -47,23 +71,44 @@ cmake --build build --config Release
4771cmake -B build -DCMAKE_BUILD_TYPE=Release
4872cmake --build build
4973./build/alloc_benchmarks
50- ./build/alloc_tests
74+ ctest --test-dir build --output-on-failure
75+ ```
76+
77+ ### With Sanitizers (Linux/macOS)
78+
79+ ``` bash
80+ # Address Sanitizer
81+ cmake -B build -DCMAKE_BUILD_TYPE=Debug \
82+ -DCMAKE_CXX_FLAGS=" -fsanitize=address -fno-omit-frame-pointer -g"
83+ cmake --build build
84+ ctest --test-dir build --output-on-failure
85+
86+ # Thread Sanitizer
87+ cmake -B build -DCMAKE_BUILD_TYPE=Debug \
88+ -DCMAKE_CXX_FLAGS=" -fsanitize=thread -g"
89+ cmake --build build
90+ TSAN_OPTIONS=" second_deadlock_stack=1 suppressions=tsan.supp" \
91+ ctest --test-dir build --output-on-failure
5192```
5293
5394## Project Structure
5495
5596```
5697fast-alloc/
5798├── src/
58- │ ├── pool_allocator.h/cpp - Fixed-size block allocator
59- │ ├── stack_allocator.h/cpp - Linear allocator with reset
60- │ └── freelist_allocator.h/cpp - General-purpose with coalescence
99+ │ ├── pool_allocator.h/cpp - Fixed-size block allocator
100+ │ ├── threadsafe_pool_allocator.h/cpp - Thread-safe pool allocator
101+ │ ├── stack_allocator.h/cpp - Linear allocator with reset
102+ │ └── freelist_allocator.h/cpp - General-purpose with coalescence
61103├── benchmarks/
62104│ └── Comprehensive performance benchmarks vs malloc/new
63105├── tests/
64- │ └── Unit tests with Catch2
65- └── docs/
66- └── Performance analysis and implementation details
106+ │ ├── Unit tests with Catch2
107+ │ └── Concurrent stress tests for thread-safe allocators
108+ ├── .github/workflows/
109+ │ └── CI with sanitizers (ASan, TSan, UBSan)
110+ └── tsan.supp
111+ └── ThreadSanitizer suppressions for Catch2
67112```
68113
69114## Usage Examples
@@ -81,6 +126,26 @@ void* obj = pool.allocate();
81126pool.deallocate(obj);
82127```
83128
129+ ### Thread-Safe Pool Allocator
130+
131+ ```cpp
132+ #include "threadsafe_pool_allocator.h"
133+ #include <thread>
134+
135+ fast_alloc::ThreadSafePoolAllocator pool(64, 1000);
136+
137+ void worker_thread() {
138+ void* obj = pool.allocate();
139+ // Thread-safe allocation
140+ pool.deallocate(obj);
141+ }
142+
143+ std::thread t1(worker_thread);
144+ std::thread t2(worker_thread);
145+ t1.join();
146+ t2.join();
147+ ```
148+
84149### Stack Allocator
85150
86151``` cpp
@@ -123,6 +188,16 @@ Standard `malloc`/`new` are general-purpose but slow for game development patter
123188
124189Custom allocators exploit specific allocation patterns for dramatic performance improvements.
125190
191+ ## Testing
192+
193+ Comprehensive test suite with Catch2:
194+
195+ - Unit tests for all allocators
196+ - Move semantics validation
197+ - Edge case handling (nullptr, overflow, alignment)
198+ - Concurrent stress tests for thread-safe variants
199+ - CI with multiple sanitizers (ASan, TSan, UBSan)
200+
126201## Licence
127202
128203MIT Licence - see [ LICENSE] ( LICENSE ) for details.
0 commit comments