Types of memory

In general, you can regard memory as being one of four types:

  • Static or global
  • String pool
  • Automatic or stack
  • Free store

When you declare a variable at the global level, or if you have a variable declared in a function as static, then the compiler will ensure that the variable is allocated from memory that has the same lifetime as the application--the variable is created when the application starts and deleted when the application ends.

When you use a string literal, the data will also, effectively, be a global variable, but stored in a different part of the executable. For a Windows executable, string literals are stored in the .rdata PE/COFF section of the executable. The .rdata section of the file is for read-only initialized ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.