Global memory management in C++ in stack or heap?

sameer karjatkar picture sameer karjatkar · Jul 23, 2009 · Viewed 61.1k times · Source

If I declare a data structure globally in a C++ application , does it consume stack memory or heap memory ?

For eg

struct AAA
{

.../.../.
../../..
}arr[59652323];

Answer

Milan picture Milan · Jul 23, 2009

Since I wasn't satisfied with the answers, and hope that the sameer karjatkar wants to learn more than just a simple yes/no answer, here you go.

Typically a process has 5 different areas of memory allocated

  1. Code - text segment
  2. Initialized data – data segment
  3. Uninitialized data – bss segment
  4. Heap
  5. Stack

If you really want to learn what is saved where then read and bookmark these:

COMPILER, ASSEMBLER, LINKER AND LOADER: A BRIEF STORY (look at Table w.5)

Anatomy of a Program in Memory

alt text