Memory Management Reference

« 1. Choosing a pool class | 4. AMC (Automatic Mostly-Copying) | 5. AMCZ (Automatic Mostly-Copying Zero-rank) »

4. AMC (Automatic Mostly-Copying)

AMC is a general-purpose automatically managed pool class. This is the most mature pool class in the MPS, intended for the majority of objects in the client program. Use this pool class unless you need a particular feature that it doesn’t provide.

“Mostly Copying” means that it uses copying garbage collection except for blocks that are pinned by ambiguous references.

It uses generational garbage collection. That is, it exploits assumptions about object lifetimes and inter-connection variously referred to as “the generational hypothesis”. In particular, the following tendencies will be efficiently exploited by an AMC pool:

  • most objects die young;

  • objects that don’t die young will live a long time.

4.1. AMC properties

4.2. AMC interface

#include "mpscamc.h"
mps_pool_class_t mps_class_amc(void)

Return the pool class for an AMC (Automatic Mostly-Copying) pool.

When creating an AMC pool, mps_pool_create_k() requires one keyword argument:

It accepts three optional keyword arguments:

  • MPS_KEY_CHAIN (type mps_chain_t) specifies the generation chain for the pool. If not specified, the pool will use the arena’s default chain.

  • MPS_KEY_INTERIOR (type mps_bool_t, default TRUE) specifies whether ambiguous interior pointers to blocks in the pool keep objects alive. If this is FALSE, then only client pointers keep objects alive.

  • MPS_KEY_EXTEND_BY (type size_t, default 4096) is the minimum size of the memory segments that the pool requests from the arena. Larger segments reduce the per-segment overhead, but increase fragmentation and retention.

For example:

MPS_ARGS_BEGIN(args) {
    MPS_ARGS_ADD(args, MPS_KEY_FORMAT, fmt);
    res = mps_pool_create_k(&pool, arena, mps_class_amc(), args);
} MPS_ARGS_END(args);