Subscribe to EDN

Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?

March 24, 2010

Back when I was deep into building embedded control systems (and snow was always 20 feet deep and going to and from school was up hill both ways), the use of dynamic memory allocation was forbidden. In fact, using compiler library calls was also forbidden in many of the systems I worked on. If we needed to use a library call, we rewrote it so that we knew exactly what it did and how. Those systems were highly dependent on predictable, deterministic real-time behavior that had to run reliably for long periods of time without a hiccup of any kind. Resetting the system was not an option, and often the system had to keep working correctly in spite of errors and failures for as long as it could – in many cases lives could be on the line. These systems were extremely resource constrained both from a memory and processing duty-cycle time perspective and we manually planned out all of the memory usage.

That was then, this is now. Today’s compilers are much better than they were then. Today’s processors include enormous amounts of memory and peripherals compared to the processors back then. Processor clock rates support much more processing per processing period than before such that there is room to waste a few cycles on “inefficient” tasks. Additionally, some of what were application-level functions back then are low-level, abstracted function calls in today’s systems. Today’s tools are more aware of memory leaks and are better at detecting such anomalies. But are they good enough for low level or deeply embedded tasks?

Do today’s compilers generate good enough code with today’s “resource rich” microcontrollers to make the static versus dynamic memory allocation a non-issue for your application space? I believe there will always be some classes of applications where using dynamic allocation, regardless of rich resources, is a poor choice. So in addition to answering whether you use or allow dynamic memory allocation in your embedded designs, please share what types of applications your answer applies to.

 

To make tracking the different series easier, I have three series running at this time. Monday posts address the Robust Design series. Wednesday posts address the Question of the Week series. Friday posts address the Extreme Processing Thresholds series.

 

To make following the Question of the Week series easier (especially with multiple overlapping series), I am including the index below to previous relevant posts. I encourage you to check out all of the posts for the question of the week series; maybe they will inspire you to share your observations. I would love to be able to consolidate different perspectives and lessons learned here. I suspect there are some valuable lessons to be gleaned from comparing such stories. If you would like to suggest a question, please contact me.

2010, March 17: Question of the Week: You know you’re an embedded developer when …

 

Posted by Robert Cravotta on March 24, 2010 | Comments (12)

March 26, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
KjellKod commented:

My experience from the embedded world (only one 'real' project so far). Good clean object oriented C++, lower layer C wrapped up for easy C++ access. NO DYNAMIC memory allocations used. But the machine was very limited with resources.


March 26, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
KjellKod commented:

My experience from the embedded world (only one 'real' project so far). Good clean object oriented C++, lower layer C wrapped up for easy C++ access. NO DYNAMIC memory allocations used. But the machine was very limited with resources.


March 25, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
embeddeddesigner commented:

Like a previous poster, I have never designed an embedded device where system failure was an acceptable performance metric (This ain't Windows). In my present industry (UPSs), the typical system is installed by the customer, turned on, and may run until it is retired (5-7 years) without a re-boot; making it extremely intolerant of memory leaks. I also follow a personal standard that if you run out of a resource, the device must degrade gracefully. For example, I must maintain a log of past events that the customer can scroll through on the front panel. Making it finite in length forces me to confront the only choices when I run out of RAM: - Stop logging, or - Overwrite the oldest event. Dynamic allocation schemes make it much more difficult to handle such scenarios and increase the chance of a catastrophic failure.


March 25, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
embeddeddesigner commented:

Like a previous poster, I have never designed an embedded device where system failure was an acceptable performance metric (This ain't Windows). In my present industry (UPSs), the typical system is installed by the customer, turned on, and may run until it is retired (5-7 years) without a re-boot; making it extremely intolerant of memory leaks. I also follow a personal standard that if you run out of a resource, the device must degrade gracefully. For example, I must maintain a log of past events that the customer can scroll through on the front panel. Making it finite in length forces me to confront the only choices when I run out of RAM: - Stop logging, or - Overwrite the oldest event. Dynamic allocation schemes make it much more difficult to handle such scenarios and increase the chance of a catastrophic failure.


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Brian S commented:

We only allow dynamic allocation... never allowed to let it go.


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Brian S commented:

We only allow dynamic allocation... never allowed to let it go.


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Glenn Edgar commented:

I use dynamic memory, but I use the dynamic memory in private heaps. Private heaps allow only a few function to use it and it can be reset without taking down the entire system. Construction of private heaps are easy as the code example in page 140- 150 of the K & R book


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Glenn Edgar commented:

I use dynamic memory, but I use the dynamic memory in private heaps. Private heaps allow only a few function to use it and it can be reset without taking down the entire system. Construction of private heaps are easy as the code example in page 140- 150 of the K & R book


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Phil Ouellette commented:

My designs all have 100% uptime requirements (I am not allowed to count on the user ever restarting the system during the lifetime of the product). The risks of a memory leak outweighs the benefits of dynamic memory allocation in my applications. I do use library functions, but my compiler vendor has lived in the deeply embedded world for a long time (Keil). In addition, we are careful to avoid using function that involve dynamic memory allocation. We also code in C not C++. We do write OO code, but manually encapsulate data and methods instead of using C++ constructs.


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Phil Ouellette commented:

My designs all have 100% uptime requirements (I am not allowed to count on the user ever restarting the system during the lifetime of the product). The risks of a memory leak outweighs the benefits of dynamic memory allocation in my applications. I do use library functions, but my compiler vendor has lived in the deeply embedded world for a long time (Keil). In addition, we are careful to avoid using function that involve dynamic memory allocation. We also code in C not C++. We do write OO code, but manually encapsulate data and methods instead of using C++ constructs.


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Andy T commented:

NFW. One crash in machine control takes out hundreds of dollars in tooling. Just to save $3 in RAM? And if you need more RAM than $10 worth of RAM in a real time system, it's time to fire the firmware people.


March 24, 2010
In response to: Question of the Week: Do you use or allow dynamic memory allocation in your embedded design?
Andy T commented:

NFW. One crash in machine control takes out hundreds of dollars in tooling. Just to save $3 in RAM? And if you need more RAM than $10 worth of RAM in a real time system, it's time to fire the firmware people.

POST A COMMENT
Display Name
captcha

Before submitting this form, please type the characters displayed above. Note the letters are case sensitive:

Advertisement
Advertisement
Advertisement
About EDN   |   Site Map   |   Contact Us   |   Subscription   |   RSS
© 2012 UBM Electronics. All rights reserved.
Use of this Web site is subject to its Terms of Use | Privacy Policy

Please visit these other UBM Canon sites

UBM Canon | Design News | Test & Measurement World | Packaging Digest | EDN | Qmed | Pharmalive | Appliance Magazine | Plastics Today | Powder Bulk Solids | Canon Trade Shows