We are proud to offer a new Multi-thread Friendly Memory Manager for FPC written in x86_64 assembly, implemented as such:

  • targetting Linux (and Windows) multi-threaded Services
  • only for FPC on the x86_64 target - use the RTL MM on Delphi or ARM
  • based on FastMM4 proven algorithms by Pierre le Riche
  • code has been reduced to the only necessary featureset for production
  • deep asm refactoring for cross-platform, compactness and efficiency
  • can report detailed statistics (with threads contention and memory leaks)
  • mremap() makes large block ReallocMem a breeze on Linux :)
  • inlined SSE2 movaps loop is more efficient that subfunction(s)
  • lockless round-robin of tiny blocks (<=128/256 bytes) for better scaling
  • optional lockless bin list to avoid freemem() thread contention
  • three app modes: default mono-thread friendly, FPCMM_SERVER or FPCMM_BOOST

Usage: include this unit as the very first in your FPC project uses clause.

Why another Memory Manager on FPC?

  • The built-in heap.inc is well written and cross-platform and cross-CPU, but its threadvar arena for small blocks tends to consume a lot of memory on multi-threaded servers, and has suboptimal allocation performance
  • C memory managers (glibc, Intel TBB, jemalloc) have a very high RAM consumption (especially Intel TBB) and panic/SIGKILL on any GPF
  • Pascal alternatives (FastMM4,ScaleMM2,BrainMM) are Windows+Delphi specific
  • Our lockess round-robin of tiny blocks is a unique algorithm among Memory Managers AFAIK
  • It was so fun deeping into SSE2 x86_64 assembly and Pierre's insight
  • Resulting code is still easy to understand and maintain, and performs very well
  • It tends to have very low fragmentation, and consume less memory than FPC alternatives, especially for multi-threaded projects
  • It is really Open Source (MPL/GPL/LGPL) and may be used on production for FPC x86_64 apps just as much as FastMM4 was for Delphi

Feedback is welcome!