The Memory Pool Library is a high-performance C++ fixed-size block memory allocator. It delivers O(1) allocation/deallocation with zero fragmentation, making it ideal for real-time and high-performance scenarios requiring frequent fixed-size allocations.
- Fixed-size block allocation
- O(1) allocation/deallocation
- Zero fragmentation
- Header-only, exception-safe
- Single-threaded (not thread safe)
MemoryBlock: Node structure for free-list ordering.MemoryPool: Stores pool metadata and free-list pointer.
Each block: [MemoryBlock header][block_size user data]
- create_memory_pool: Allocate pool
- destroy_memory_pool: Destroy pool & all memory
- allocate_block: Retrieve block from pool
- free_block: Return block to pool
See detailed use-case examples in the full documentation.
- Allocation failures return
nullptr - Destruction and freeing operations are null-safe
| Operation | Time Complexity | Space Overhead |
|---|---|---|
| Pool Creation | O(n) | O(n) |
| Allocation | O(1) | O(1) |
| Deallocation | O(1) | O(1) |
| Pool Destruction | O(n) | O(1) |
Not thread safe. Use only in single-threaded contexts or wrap externally.
- Fixed block size
- No automatic resizing/growing
- User must track allocations
- No built-in thread safety
- Double/free detection and invalid free (canaries, allocation bitmaps)
- Use-after-free mitigations (debug poison)
- Stricter alignment guarantees
- Explicit base pointer tracking (for robust destruction)
- Enhanced parameter validation
- Optional thread-safe variants (locking, lock-free, per-thread pools)
- NUMA node and TLS-awareness
- Dynamic pool growth/shrinking via slab superblocks
- Multi-size bin/slab allocator front-end
- Custom alignment per-block
- Placement-new helpers and C++ object lifecycle integration
- Introspection/statistics API
- Memory tagging/pool ownership ID
- Choose between intrusive or side metadata
- Bulk allocation/free API
- Pool cacheline padding for less false sharing
- Compile-time policies for sync, debug, and allocation
- RAII C++ pool handle and block wrappers
- Consistent error reporting, standard allocator compatibility
- Advanced and multithreaded usage docs
- Allocation source abstraction (malloc/mmap, guard pages)
- Tooling/sanitizer-friendly
- Free-list hardening (randomization, pointer encryption, checksums)
- Wipe/zero freed blocks on request for sensitive use
- Property and fuzz tests for allocator semantics
- Full unit and stress suite (alignment, cross-pool, stats)
- Store and reference actual base pointers per slab (robust slab/capacity growth and safe destruction)
- Use
align_uputilities for block layout - Optionally maintain a debug allocation bitmap
For deeper integration in production environments, follow these principles to ensure maximal safety, scalability, and diagnostics as your pool is adapted and scaled.