Skip to content

Bishal-9/MemoryPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memory Pool Library Documentation


Overview

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.

Features

  • Fixed-size block allocation
  • O(1) allocation/deallocation
  • Zero fragmentation
  • Header-only, exception-safe
  • Single-threaded (not thread safe)

Architecture

Core Components

  • MemoryBlock: Node structure for free-list ordering.
  • MemoryPool: Stores pool metadata and free-list pointer.

Memory Layout

Each block: [MemoryBlock header][block_size user data]

API Reference

Pool Management

  • create_memory_pool: Allocate pool
  • destroy_memory_pool: Destroy pool & all memory

Block Operations

  • allocate_block: Retrieve block from pool
  • free_block: Return block to pool

Usage Patterns

See detailed use-case examples in the full documentation.

Error Handling

  • Allocation failures return nullptr
  • Destruction and freeing operations are null-safe

Performance Characteristics

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)

Thread Safety

Not thread safe. Use only in single-threaded contexts or wrap externally.

Limitations

  • Fixed block size
  • No automatic resizing/growing
  • User must track allocations
  • No built-in thread safety

Future Improvements

Safety/Correctness

  • 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

Concurrency & Scalability

  • Optional thread-safe variants (locking, lock-free, per-thread pools)
  • NUMA node and TLS-awareness

Flexibility and Features

  • 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

Performance Enhancements

  • Bulk allocation/free API
  • Pool cacheline padding for less false sharing
  • Compile-time policies for sync, debug, and allocation

API and UX Improvements

  • RAII C++ pool handle and block wrappers
  • Consistent error reporting, standard allocator compatibility
  • Advanced and multithreaded usage docs

Portability and Integration

  • Allocation source abstraction (malloc/mmap, guard pages)
  • Tooling/sanitizer-friendly

Security Considerations

  • Free-list hardening (randomization, pointer encryption, checksums)
  • Wipe/zero freed blocks on request for sensitive use

Testing and Verification

  • Property and fuzz tests for allocator semantics
  • Full unit and stress suite (alignment, cross-pool, stats)

Implementation Starting Hints

  • Store and reference actual base pointers per slab (robust slab/capacity growth and safe destruction)
  • Use align_up utilities 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors