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:
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.
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
|Feature||Number of Bytes||Percentage|
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.