1. Overview of the Memory Pool System

The Memory Pool System is a very general, adaptable, flexible, reliable, and efficient memory management system. It permits the flexible combination of memory management techniques, supporting manual and automatic memory management, inline allocation, finalization, weakness, and multiple concurrent co-operating incremental generational garbage collections. It also includes a library of memory pool classes implementing specialized memory management policies.

The MPS has been in development since 1994 and deployed in successful commercial products since 1997. Bugs are almost unknown in production. It is under continuous development and support by Ravenbrook.

The MPS is distributed under an open source license. The license is designed to make it possible for you to use the MPS in your own projects, provided that you either don’t distribute your product, or your product is open source too.

If the licensing terms aren’t suitable for you (for example, you’re developing a closed-source commercial product or a compiler run-time system) you can easily license the MPS under different terms from Ravenbrook by arrangement. Please contact us at mps-questions@ravenbrook.com for details.

1.1. Supported target platforms

The MPS is currently supported for deployment on:

  • Windows Vista or later, on IA-32 and x86-64, using Microsoft Visual C/C++;
  • Linux 2.6 or later, on IA-32 using GCC and on x86-64 using GCC or Clang/LLVM;
  • FreeBSD 7 or later, on IA-32 and x86-64, using GCC or Clang/LLVM;
  • macOS 10.4 or later, on IA-32 and x86-64, using Clang/LLVM.

The MPS is highly portable and has run on many other processors and operating systems in the past (see Building the Memory Pool System). Most of the MPS is written in very pure ANSI C and compiles without warnings on anything.

Warning

If you are running a multi-threaded 32-bit application on 64-bit Windows 7 via the WOW64 emulator, then you must install this hotfix from Microsoft. See WOW64 bug: GetThreadContext() may return stale contents for a description of the problem.

1.2. Technical introduction

The figure below gives a simplified picture of a program’s memory from the point of view of the Memory Pool System.

Diagram: Overview of the Memory Pool System.

Overview of the Memory Pool System.

The arena is the top-level data structure in the MPS. An arena is responsible for requesting memory(3) from the operating system (and returning it), for making memory available to pools, and for garbage collection. Multiple arenas are supported, but it’s usually best to have only one arena in your program, because the MPS can’t collect cyclic structures that span multiple arenas. See Arenas.

The MPS is designed to co-operate with other memory managers (for example malloc and free(2) in C, or operators new and delete in C++), so you need not move all your memory management to the MPS at once, and you can co-operate with libraries that use other allocation mechanisms.

Within the arena you create one or more pools. A pool is responsible for requesting memory from the arena and making it available to your program. See Pools.

Pools belong to pool classes that specify policies for how their memory is managed. Some pools are manually managed (you must explicitly return memory to the pool, for example by calling mps_free()) and others are automatically managed (the garbage collector reclaims unreachable blocks). See Pool reference.

Formatted pools need you to tell them how to scan for references to allocated blocks. See Scanning.

The arena needs you to tell it how to find your roots: references to allocated blocks that are stored in static data, in memory not managed by the MPS, in your program’s registers, or on its control stack. See Roots.

The MPS is designed to work with multi-threaded programs. Functions in the C interface are thread safe, except in a few documented cases. See Threads. The allocation point protocol provides fast lock-free allocation on multiple threads simultaneously. See Allocation.

The garbage collector is incremental: it proceeds in small steps interleaved with the execution of your program, so there are no long waits. The garbage collector is designed to work efficiently with multiple pools, and in cases where there are many references between objects in different pools. See Garbage collection.

1.3. What next?

For a much more detailed technical overview of the MPS, see Brooksby (2002).

If you’re going to try it out, see Building the Memory Pool System.

If you have a program in need of memory management, then you’ll want to learn how to integrate it with the Memory Pool System. See Garbage collecting a language with the Memory Pool System.

If you want to know more technical details, they appear in the Reference.