emRun++
The C++ runtime library for embedded applications
emRun++ is a complete C++ standard library specifically designed and optimized for GCC/LLVM-based toolchains and embedded systems.
Overview
emRun++ is a complete C++ standard library for use with any toolchain. It is specifically tweaked for embedded systems and applications. As a modern programming language, C++ is becoming increasingly important in the embedded sector offering developers more and more options. With this in mind, emRun++ is constantly being enhanced to meet the most modern C++ standards.
emRun++ is also part of SEGGER's Embedded Studio IDE. Included in the ready-to-use toolchain and C runtime library of Embedded Studio, it is available out of the box and has all the features that make object-oriented programming (OOP) fast and easy.
Key features
- Comprehensive C++ standard library
- Compatibility with common C++ standards, C++17
- Complete integration with emRun
- Dynamic memory management, optimized for embedded systems
- Exception handling, including target unwinding on all supported targets
Modern C++ features
emRun++ implements classes and functions according to C++ standards. It also supplements the language features and incorporates the complete feature set of the C++17 standard defined by the International Organization for Standardization (ISO).
emRun++ provides all standard C++ header files together with wrappers for the C runtime library headers. The implementation includes mangled names of standard C functions, such as cos(float) and cos(double) to its C equivalents cosf() and cos().
Dynamic memory allocation
Modern C++ applications rely on dynamic memory allocation. Objects are present in memory only while they are being used. Long-lived objects are usually created with “new” and destroyed with “delete”. While C++ takes care of calling objects’ constructors and destructors respectively, the regular C runtime library basically does the memory management.
emRun++ implements "new" and "delete" to use the alloc and free routines of the C runtime library emRun, which provides efficient use of heap memory, requiring the least overhead.
Exception handling
C++ defines the use of exceptions, in contrast to C where it is the user’s responsibility to manually recover from an error and pass errors up to all callers or to run into a fault. Exception handling offers a systematic and robust approach to cope with errors that cannot be recovered from locally. Exceptions can be thrown in case of an error and are passed up the call stack up to a point where they are caught and handled.
When an exception is thrown in a try block, all objects constructed within the block need to be destroyed, and the stack is unwound. To provide exception support, emRun++ implements the target architecture-dependent stack unwinding for all supported architectures.
Low-level support
C++ compilers define an application binary interface (ABI) which, for example, defines how objects are arranged, how name mangling works, or how virtual functions are implemented.
emRun++ implements the low-level functions of the C++ ABI to which the compiler implicitly adds calls in code generation. This enables the C++ library to be used out-of-the-box with any toolchain.
Memory footprint
Arm (32-bit)
ROM Usage [Bytes] | |||
---|---|---|---|
Test Project [1] | emRun++ [2] | libstdc++ [3] | |
Empty | 496 | 924 | |
STL_List1 | 1,192 | 69,409 | |
STL_List2 | 1,396 | 69,557 | |
STL_Map1 | 1,464 | 70,217 | |
STL_Map2 | 2,080 | 71,661 | |
STL_Set1 | 1,476 | 69,993 | |
STL_Set2 | 1,584 | 70,101 |
RISC-V (32-bit)
ROM Usage [Bytes] | |||
---|---|---|---|
Test Project [1] | emRun++ [4] | libstdc++ [5] | |
Empty | 676 | 858 | |
STL_List1 | 1,868 | 90,848 | |
STL_List2 | 2,276 | 91,012 | |
STL_Map1 | 2,380 | 91,620 | |
STL_Map2 | 3,536 | 93,216 | |
STL_Set1 | 2,408 | 91,370 | |
STL_Set2 | 2,600 | 91,464 |
RISC-V (64-bit)
ROM Usage [Bytes] | |||
---|---|---|---|
Test Project [1] | emRun++ [6] | libstdc++ [7] | |
Empty | 542 | 888 | |
STL_List1 | 1,414 | 87,314 | |
STL_List2 | 1,622 | 87,496 | |
STL_Map1 | 1,758 | 88,104 | |
STL_Map2 | 2,554 | 89,766 | |
STL_Set1 | 1,768 | 87,848 | |
STL_Set2 | 1,878 | 87,952 |
[1] Source code available at https://kb.segger.com/emRun++
[2] SEGGER Embedded Studio for ARM version 6.32b, emRun++, GNU Toolchain, ARMv7M
[3] GNU Arm Embedded Toolchain version 10.3-2021.10, libstdc++, ARMv7M
[4] SEGGER Embedded Studio for RISC-V version 6.32b, emRun++, GNU Toolchain, RV32IMAC
[5] SiFive GNU Embedded Toolchain for RISC-V version 2020.12.8, libstdc++, RV32IMAC
[6] SEGGER Embedded Studio for RISC-V version 6.40, emRun++, GNU Toolchain, RV64IMAC
[7] SiFive GNU Embedded Toolchain for RISC-V version 2020.12.8, libstdc++, RV64IMAC