15 October 2025 by Phillip JohnstonTable of Contents: Visualizing Memory Allocation Allocation Schemes Common System Policies Problems Arising from Dynamic Memory Allocation Runtime Problems Structural Problems Implementations References Visualizing Memory Allocation Here are some useful articles that explain how memory allocation typically works, including helpful diagrams and other visualizations. Visual overview of a custom malloc() implementation Memory Allocation, an article that includes a visual overview of how dynamic memory allocation works Allocation Schemes First-fit Free List Buddy Allocation Slab allocation Fixed-size block allocation (Memory pools) Intrusive containers (lists, maps, etc.) Individual elements put into the container store all the metadata …
Continue reading “Memory Allocation”
I learned about three new GCC compiler/linker flags this week that are helpful for monitoring a system’s memory usage. I was surprised that I hadn’t previously run across them, and it seems like other developers in my network didn’t know about these flags either! Perhaps this isn’t too out of the ordinary considering that two …
Continue reading "Three GCC Flags for Analyzing Memory Usage"
The memory library is developed by Jonathan Müller, a C++ library developer and author of foonathan::blog(). This library provides an new STL-compatible C++ memory allocator called RawAllocator. The RawAllocator is similar to the standard Allocator but is easier to use. The library also provides a BlockAllocator type which can be used for allocating large blocks …
Continue reading "foonathan/memory: Simplifying the C++ Memory Allocator"
Updated 20191019 In the past I’ve shared malloc implementations which are built using a first-fit free list and ThreadX. Today I’d like to share a malloc implementation based on another popular RTOS: FreeRTOS. Table of Contents: FreeRTOS Memory Allocation A Simple FreeRTOS malloc A Simple FreeRTOS free Heap Initialization with heap_5 Heap 5 Groundwork Adding …
Continue reading "Implementing Malloc With FreeRTOS"
Recall in the aligned_malloc article that we noted the need to pair aligned_malloc with aligned_free. Using the wrong free call can cause serious problems, as we have modified the pointer that malloc originally returned to us. This problem of pairing allocators and deleters also applies in other situations: new must be paired with delete, while …
Continue reading "C++ Smart Pointers with Aligned Malloc/Free"
Embedded systems often have requirements for pointer alignment. These alignment requirements exist in many places, some including: General device/CPU requirements Unaligned access may generate a processor exception with registers that have strict alignment requirements Cache line size You don’t want to accidentally perform clean/invalidate operations on random data Peripheral hardware requirements DMA and USB peripherals …
Continue reading "Generating Aligned Memory"
I previously provided a free-list malloc implementation. In this article, you will see how to use an RTOS with a memory allocator to build malloc and free. Table of Contents ThreadX Creating a Byte Pool Allocating Memory Freeing Memory Initialization malloc free Hiding the Initialization Functions Pointers & Atomics Memory Definition Malloc as a Function …
Continue reading "Implementing Malloc with ThreadX"
Now that we’ve seen some useful C++ examples that can be applied to embedded systems, you’re probably curious about getting C++ code up and running on your embedded platform. If you try linking C++ code for your platform, you might find that you have numerous undefined symbol errors. Unfortunately, C++ runtimes are not provided for …
Continue reading "Implementing Malloc: First-fit Free List"