Monday, September 5, 2011

[C++] Storage duration, Scope, and Linkage

Quoted from "C++ Primer Plus, Fifth edition":


C++ uses three separate schemes for storing data, and the schemes differ in how long they preserve data in memory:
• Automatic storage duration—Variables declared inside a function definition—including
function parameters—have automatic storage duration. They are created when program
execution enters the function or block in which they are defined, and the memory
used for them is freed when execution leaves the function or block. C++ has two kinds
of automatic storage duration variables. (Automatic and register)

• Static storage duration—Variables defined outside a function definition or else by
using the keyword static have static storage duration. They persist for the entire time a
program is running. C++ has three kinds of static storage duration variables.
(external, internal, and no linkage)

• Dynamic storage duration—Memory allocated by the new operator persists until it is
freed with the delete operator or until the program ends, whichever comes first. This
memory has dynamic storage duration and sometimes is termed the free store.




No comments:

Post a Comment

Fork me on GitHub