: Essential functions for input/output (like std::cout ), string manipulation, and math are part of the runtime libraries. Key Components of the Runtime Environment
– It is thread‑safe but the guard check adds a small overhead (one atomic read). For very hot paths, consider a separate thread‑safe lazy initialization pattern.
C++ is built on top of C. Therefore, the C++ runtime includes or depends on the C runtime. On Windows, this is often the Universal C Runtime (UCRT). On Linux, it is typically glibc .
The runtime manages the . When you type new int , you are asking the runtime to find a free block of memory.
– Replace with constexpr or lazy initialization (Meyers singletons) to reduce startup time and avoid order‑of‑initialization bugs.
– Many codebases compile with -fno-rtti to save binary size (e.g., game engines, embedded systems). But you lose dynamic_cast and typeid .
At its core, the C++ runtime bridges the gap between your source code and the OS. It provides several critical services:
Windows uses a linked list of exception registration records on the stack ( fs:[0] on x86, __except_list on x64). Each function prolog pushes a EHRegistrationNode that points to a handler. The runtime ( RtlUnwind ) walks this list. The cost is similar: zero overhead in normal execution but complex metadata for each function containing try/catch blocks.