9. MFS (Manual Fixed Small)

MFS is an manually managed pool class for small objects of fixed size.

Unlike other manual pool classes, it is not subject to internal fragmentation: if the population remains bounded, the memory usage remains bounded too. On the other hand, unlike MVT (Manual Variable Temporal) and MVFF (Manual Variable First Fit) it does not return unused memory to the arena for reuse by other pools.

The implementation is very simple: unlike most other pool classes which store their control structures separately from the allocated blocks, MFS maintains a stack of free blocks using a pointer in the free block. mps_alloc() pops this stack and mps_free() pushes it.

9.1. MFS properties

9.2. MFS interface

#include "mpscmfs.h"
mps_pool_class_t mps_class_mfs(void)

Return the pool class for an MFS (Manual Fixed Small) pool.

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

  • MPS_KEY_MFS_UNIT_SIZE (type size_t) is the size of blocks that will be allocated from this pool, in bytes (1). It must be at least one word.

In addition, mps_pool_create_k() accepts one optional keyword argument:

  • MPS_KEY_EXTEND_BY (type size_t, default 65536) is the size of block that the pool will request from the arena. It must be at least as big as the unit size specified by the MPS_KEY_MFS_UNIT_SIZE keyword argument. If this is not a multiple of the unit size, there will be wasted space in each block.

For example:

MPS_ARGS_BEGIN(args) {
    MPS_ARGS_ADD(args, MPS_KEY_MFS_UNIT_SIZE, 1024);
    MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, 1024 * 1024);
    res = mps_pool_create_k(&pool, arena, mps_class_mfs(), args);
} MPS_ARGS_END(args);