Skip to Main Content
Programming Embedded Systems, 2nd Edition
book

Programming Embedded Systems, 2nd Edition

by Michael Barr, Anthony Massa
October 2006
Intermediate to advanced content levelIntermediate to advanced
336 pages
9h 13m
English
O'Reilly Media, Inc.
Content preview from Programming Embedded Systems, 2nd Edition

Reducing Memory Usage

In some cases, RAM rather than ROM is the limiting factor for your application. In these cases, you’ll want to reduce your dependence on global data, the stack, and the heap. These are all optimizations better made by the programmer than by the compiler.

Because ROM is usually cheaper than RAM (on a per-byte basis), one acceptable strategy for reducing the amount of global data might be to move constant data into ROM. This can be done automatically by the compiler if you declare all of your constant data with the keyword const. Most C compilers place all of the constant global data they encounter into a special data segment that is recognizable to the locator as ROM-able. This technique is most valuable if there are lots of strings or table-oriented data that will not change at runtime.

If some of the data is fixed once the program is running but not necessarily constant, the constant data segment could be placed in a hybrid memory device such as flash or EEPROM. This memory device could then be updated over a network or by a technician assigned to make the change. An example of such data is the sales tax rate for each locale in which your product will be deployed. If a tax rate changes, the memory device can be updated, but additional RAM can be saved in the meantime.

Stack size reductions can also lower your program’s RAM requirement. One way to figure out approximately how much stack you need is to fill the entire memory area reserved for the stack with a ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming with STM32: Getting Started with the Nucleo Board and C/C++

Programming with STM32: Getting Started with the Nucleo Board and C/C++

Donald Norris

Publisher Resources

ISBN: 0596009836Supplemental ContentErrata Page