Living dangerously with - or without - malloc() - Embedded.com

Living dangerously with – or without – malloc()

Most software developers stick to the straight and narrow in their use ofC’s malloc() library function – and its faithful companion free ()- in the constrained firmware environment of most embedded designs. But inthis week’s Embedded.com Tech Focus Newsletter , Colin Walls in “Dynamicmemory and heap contiguity“ provides some tips on how to livedangerously using dynamic allocation and do so with reasonable safety.

In hisarticle, Colin does an excellent job in describing some new techniquesthat he’s convinced me are worth trying, especially if you are looking fora way out of the performance and deterministic straight jacket that dependenceon malloc imposes. 

Many current and future designs using 32 bit and multicore MCU implementationswill require either a safer way to use dynamic allocation or some way toextend static allocation. Included in the newsletter are a number of designarticles and blogs on various static and dynamic techniques to achieve this.In addition, a number of other articles worth checking out include:

Memory allocation in C
Mastering stack and heap for memory allocation reliability
Building a user space library for dynamic memory analysis
Tackling memory allocation in multicore/multithreaded apps

Colin and the other contributors to Embedded.com haven't been the only oneslooking at ways to live dangerously. Here are a few papers I found on howto use dynamic allocation in a number of next generation designs:

A scalable lock-free dynamic memory allocator
Dynamic memory allocators for real-time embedded systems
Using Palloc for parallel dynamic memory allocation
Dynamic memory management for embedded real-time systems
Efficient dynamic heap allocation of scratchpad memory

As you read these various perspectives of the issue of dynamic versus staticmemory allocation, keep in mind the warning that Colin includes in his article:

The word “dynamic” should – and normally does – ring alarm bellswith embedded software developers,” he writes. “The dynamic allocation/creationof anything is fraught with problems in real time and deeply embedded systems,so, wherever possible, static alternatives should be considered.

But, he adds, while dynamic memory allocation is a good example of wherethis caution is wise, a clear understanding of the issues involved can leadto implementations that are appropriate for your embedded design, withoutliving too dangerously.

Embedded.com Site Editor Bernard Cole is also editor of thetwice-a-week Embedded.comnewsletters as well as a partner in the TechRite Associates editorialservices consultancy. He welcomes your feedback. Send an email to , or call928-525-9087.

See more articles and column like this one on Embedded.com. Signup for the Embedded.com newsletters .Copyright © 2013 UBM–All rights reserved.

1 thought on “Living dangerously with – or without – malloc()

  1. Embedded programmers sometimes rely on malloc() and free() to allocate and free fixed-sized objects. If this is your use case, then a general-purpose heap manager is a huge overkill. malloc() and free() are designed for varying sized objects, which require

    Log in to Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.