Memory Structure of Programs
A
program when loaded into memory has the following structure:
Text
Segment:
Contains executable instructions of the program. It’s a
read-only section.
Initialized
Data Segment:
Contains global/static variables and is further divided as:
Read-only
literals like “Some string”
Writable
globals and static variables.
Uninitialized
Data Segment:
Contains global and static variables too but those which have not
been initialized. Usually, they are initialized to 0.
Stack:
This is where all the temporary and local variables are stored.
Heap:
This is where all the dynamically allocated variables are stored.
Heap
and stack grow opposite to each other and if they grow so much that
they meet or tend to overshoot each other, then it results in memory
problem usually leading to emergency termination of the program by
the OS.
|