Computer program memory is organized into following:
- Data Segment (Data + Bss + Heap)
- Stack
- Code Segment
Data Segment :
Data area contains global and static variables used by the program that are explicitly initialized with a value.This segment further can be defined into read-only area and read-write area.
For instance , string defined under global area like , char s[]=”Hello World” , variable int a=10 , would be stored in initialized read-write area because these values can be modified later, and a statements
like const char *string =”Hello World” to be stored in read-only area.
Ex. static int i=10 will be stored in the data segment.
BSS Segment:
The BSS segment, also known as uninitialized data, starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code. For instance a variable declared static int i; would be contained in the BSS segment.
Heap Area.
The heap area begins at the end of the BSS segment and grows to larger addresses from there.The heap area is used and managed for Dynamic Memory Allocation (DMA) by malloc, calloc, realloc and free functions.The heap area is shared by all shared libraries and dynamically loaded modules in process.
Stack Area
The stack area is located in the higher part of memory.Stack area is used for loading , unloading the functin and for declaring local variables. The stack area traditionally adjoined the heap area and they grew towards each other.