Repository navigation
StackAllocator v1.0.0
The first stable release of StackAllocator, a fixed-capacity, bump-pointer stack allocator for modern C++.
Highlights
- O(1) bump-pointer allocation via
allocate(). - In-place construction and destruction of arbitrary types via
create<T>()/destroy(). - RAII scope guard via
StackScopefor automatic, exception-safe rollback. - Marker-based checkpoints (
getMarker()/freeToMarker()) for stack-like, LIFO rollback of allocations, with no fixed nesting-depth limit. reset()for O(1) bulk reclamation of the entire buffer.- Alignment-aware allocation, including over-aligned types, bounded by a per-instance alignment ceiling set at construction.
owns()for validating pointer provenance against a specific allocator instance.- Optional, zero-cost-when-disabled allocation statistics via a compile-time
EnableStatsflag. - Move construction and move assignment support.
- Contract-based (assert-driven) precondition enforcement, documented consistently across the API.
- Exception-safety: allocation and constructor failures propagate without corrupting stack state.
Performance
The implementation is designed with performance and memory efficiency in mind.
- A single upfront buffer allocation eliminates per-allocation heap traffic.
- Bump-pointer allocation keeps
allocate()/create()to a handful of arithmetic operations. - Marker-based rollback reclaims an entire batch of allocations in O(1), without touching each one individually.
reset()reclaims the whole buffer in O(1), regardless of how many objects were allocated.- Exhaustion is a plain bounds check and a
nullptrreturn — no exceptions, no reallocation. - Alignment is resolved via bit-shift arithmetic rather than a general modulo/division path.
owns()is a pure range check against a single base pointer and capacity — no per-allocation bookkeeping to search.
Benchmarks
Measured against stdStack (a naive, dynamically-growing baseline) at 10K / 100K / 1M
iterations. Full results: benchmarks/results/v1_0_0.md.
| Operation | StackPro (1M) | stdStack (1M) | Δ |
|---|---|---|---|
| Allocate() @ 64 MiB Buffer | 308.33 us | 17.38 s | +5635372.3% |
| Allocate() 4096-byte Aligned | 309.12 us | 11.10 s | +3589567.1% |
| Allocate() At Capacity (Failure Path) | 308.35 us | 1.78 s | +578002.8% |
| Reset() Alone | 308.34 us | 953.03 us | +209.1% |
| Reset() + Refill | 65.48 ms | 128.47 ms | +96.2% |
| Allocate() Large | 660.43 us | 1.28 ms | +93.2% |
| Allocate() Over-aligned | 753.58 us | 1.29 ms | +70.8% |
| Create() Trivial Ctor | 1.31 ms | 1.79 ms | +36.9% |
| Create() Non-trivial Ctor | 2.51 ms | 3.37 ms | +33.9% |
| Destroy() Non-trivial Dtor | 639.55 us | 647.51 us | +1.2% |
| Destroy() Trivial Dtor | 308.33 us | 308.31 us | -0.0% |
| Construction | 29.96 ms | 7.48 ms | -75.0% |
StackPro's fixed-buffer, bump-pointer design pays off most on the exhaustion path
(a bounds check and a nullptr return versus stdStack actually reallocating and
copying), large or over-aligned buffers, and bulk churn (Reset() + refill), where
stdStack's per-call bookkeeping and growth strategy show up directly. The
alignment and capacity-growth results are the most dramatic: stdStack's cost
scales with buffer size and requested alignment, while StackPro's stays flat
regardless of either, since it never reallocates.
The trade-off: the buffer is allocated once, eagerly and aligned, at construction —
so Construction is consistently slower than stdStack's lazy setup. Destroy()
is roughly a wash either way, since both implementations ultimately just run the
same destructor; StackPro adds nothing on top of that, but it doesn't reclaim
anything faster either.
Testing
The project includes a comprehensive test suite covering:
- Unit tests
- Integration tests
- Lifecycle tests
- Move semantics
- Regression tests
- Exception safety
- Allocation failure handling
- Marker-based rollback, including nested checkpoints
StackScopeRAII behavior- Alignment behavior
- Ownership validation (
owns()) - Statistics tracking
- External synchronization contracts
Code Coverage
The current test suite achieves:
- 100.0% line coverage (93/93 lines)
- 100.0% function coverage (47/47 functions)
Coverage reports exclude test infrastructure and third-party dependencies, focusing on the StackPro library implementation.
Continuous Integration
Automated builds and tests are configured for:
- GCC — Debug
- GCC — Release
- Clang — Debug
- Clang — Release
- MSVC — Debug
- MSVC — Release
- AppleClang — Debug
- AppleClang — Release
Release
This release represents the first stable version of StackAllocator and establishes the initial API, memory-management design, testing infrastructure, and cross-platform CI pipeline.
Installation
Clone the repository and integrate StackAllocator into your C++ project using the provided CMake configuration.
See the project documentation for build instructions, API usage, and integration details.