Skip to the content.

Memory Management

[TOC]


This is an overview of the memory management features implemented in src/mmt_core/src/memory.c.

Scope

Implementation

Each chunk of allocated memory is prefixed with the size of the chunk. Global counters on allocated and freed memory are also maintained; those counters are accessible through mmt_meminfo() (src/mmt_core/private_include/memory.h:25, internal API).

MMT Memory Management

Basic Usage

Just use mmt_malloc(), mmt_realloc() and mmt_free() instead of malloc(), realloc() and free(), respectively.

The memory allocator does the housekeeping in a (hopefully) transparent way.

’'’Don’t check for allocation errors’’’, this is useless most of the time (see the following section). Just assume that memory allocation was successful.

Failure Management

The general rule is that any failed attempt to allocate memory should result in a call to libc::abort().

Recovery attempts are useless (unless part of a well-designed fail-safe architecture).

There are several reasons for this:

On modern operating systems, with huge amounts of RAM and swap space, a virtually unlimited amount of memory should be assumed.

Let’s concentrate on CPU usage instead, and remember: free the mallocs ;-)