$ show pleriche/FastMM4
FastMM4 is a production-grade drop-in replacement memory manager for Delphi and C++Builder on Windows. It replaces the default RTL allocator with a multi-threaded, low-fragmentation design organized into three tiers: small blocks (binned by size class), medium blocks (linked-list pools with bitmap-based binning), and large blocks (VirtualAlloc). The core logic lives in FastMM4.pas, a single monolithic unit, with FastMM4Options.inc providing extensive compile-time feature toggles (FullDebugMode, leak reporting, alignment, memory sharing, etc.). This is library code — there is no UI, no data pipeline, and no business logic; the only executables are demo applications (e.g., a Usage Tracker VCL form) and the BorlndMM.dll replacement for C++Builder.
The LLM identified 4 files worth highlighting for reuse:
Implements TLFStack, a lock-free stack using CAS (compare-and-swap) operations with performance measurement and alignment considerations. Self-contained and extractable for any lock-free LIFO need.
Implements TStaticCollector, a lock-free generational data collector that aggregates allocation patterns (sorted by count) across generations. Demonstrates a reusable pattern for merging sorted, count-based data without locks.
Contains the PatchProc pattern: in-memory code patching using VirtualProtect to rewrite function prologues. Reusable for API hooking and runtime instrumentation scenarios.
The core memory manager. Implements a three-tier allocator: small blocks (binned by size), medium blocks (linked-list pools with bitmap binning), and large blocks (VirtualAlloc). The binning and pool management patterns are the architectural heart of FastMM and are instructive for any custom allocator design.