
139
Chapter 10
In this chapter:
• Increasing Code
Efficiency
• Decreasing Code Size
• Reducing Memory
Usage
• Limiting the Impact
of C++
10
10. Optimizing Your
Code
Things should be made as simple as possible,
but not any simpler.
—Albert Einstein
Though getting the software to work correctly seems like the logical last step for a
project, this is not always the case in embedded systems development. The need
for low-cost versions of our products drives hardware designers to provide just
barely enough memory and processing power to get the job done. Of course, dur-
ing the software development phase of the project it is more important to get the
program to work correctly. And toward that end there are usually one or more
“development” boards around, each with additional memory, a faster processor, or
both. These boards are used to get the software working correctly, and then the
final phase of the project becomes code optimization. The goal of this final step is
to make the working program run on the lower-cost “production” version of the
hardware.
Increasing Code Efficiency
Some degree of code optimization is provided by all modern C and C++ compil-
ers. However, most of the optimization techniques that are performed by a com-
piler involve a tradeoff between execution speed and code size. Your program can
be made either faster or smaller, but not both. In fact, an improvement in one of
these areas can have a ...