EmbeddedRelated.com
The 2026 Embedded Online Conference

Memory allocation in C

Leslie Aldridge
Still RelevantIntermediate

This article is about dynamic memory allocation in C in the context of embedded programming. It describes the process of dynamically allocating memory with visual aids. The article concludes with a practical data communications switch example which includes a sample code in C.


Summary

This article explains dynamic memory allocation in C with an embedded-systems focus, using visual aids to show how the heap changes over time. It concludes with a practical data-communications switch example and a complete C sample to illustrate real-world pitfalls and techniques.

Key Takeaways

  • Explain how malloc/free manipulate the heap and how fragmentation develops in constrained systems
  • Identify common pitfalls of using dynamic allocation in embedded firmware (leaks, fragmentation, non-determinism)
  • Apply mitigation strategies such as fixed-size pools, slab allocators, and limiting runtime allocation
  • Analyze a concrete data-communications switch example and adapt the sample C code for embedded targets

Who Should Read This

Embedded and firmware engineers with some C experience who need to understand the trade-offs of dynamic memory use in microcontroller and RTOS environments.

Still RelevantIntermediate

Topics

Firmware DesignBare-Metal ProgrammingRTOSTesting/Debug

Related Documents


The 2026 Embedded Online Conference