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];
Global data structures or global variables are not consumed by stack or heap. They basically allocated in a fixed memory block, which remains unchanged.
Global variables are stored in the data section. Unlike the stack, the data region does not grow or shrink — storage space for globals persists for the entire run of the program. Finally, the heap portion of memory is the part of a program's address space associated with dynamic memory allocation.
in C, variables are allocated and freed using functions like malloc() and free() the heap is large, and is usually limited by the physical memory available. the heap requires pointers to access it.
The major difference between Stack memory and heap memory is that the stack is used to store the order of method execution and local variables while the heap memory stores the objects and it uses dynamic memory allocation and deallocation.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With