1.4. Working With Embedded Systems

1.4.1. The Problem

There are hidden costs concerning memory resources when programming in C++. On a desktop system with plenty of virtual memory you don't neccessarily recognise it. But working with embedded systems is different as there is only a limited amount of physical memory available.

For that reasons it is important to know the places where he compiler adds additional code:

Standard Template Library (STL)

Templates and other inline code may increase the resulting footprint of the binary.


After throwing an exception the complier must cleanup and destroy all automatic objects in the previous scopes. This bookkeeping consumes space as well.

Runtime Type Information (RTTI)

To provide information about an object at runtime the compiler includes data like the class name or the inheritance tree in the binary.

The following table shows the the size of the log4sendpp library when compiled with different settings. The size ranged from around 132KiB with the default settings down to 94KiB with as many features disabled as possible.

Table 1.1. Memory Consumption of C++ Code

FeatureNumber of BytesPercentage
RTTI1KiB < 1%
Library Code132KiB68%

Experience from another project suggests a code reduction of around 15% when using an optimzed STL. Of course these values may differ significantly from system to system.