Dynamic memory management
The C++ standard defines the following storage durations for objects:
- Automatic storage duration: Objects with automatic storage duration are automatically created and destroyed as the program enters and exits the block in which they are defined. These are typically local variables within functions, except those declared
static
,extern
, orthread_local
. - Static storage duration: Objects with static storage duration are allocated when the program starts and deallocated when the program ends. All objects declared at the namespace scope (including the global namespace) have this static duration, plus those declared with
static
orextern
. - Thread storage duration: Introduced in C++11, objects with thread storage duration are created and destroyed with the thread in which they are defined, allowing each thread to have its own instance of a variable. They are declared with the
thread_local
specifier. - Dynamic storage duration: Objects...