Types of memory
Memory layout in C
Whenever program is compiled five types of memories are given to the program to carry out its function
· Text Segment
· Initialized data segment
· Uninitialized data segment
· Stack
· Heap
Text Segment-
Also known as the code segment
Contains executable instructions
Text segment is placed below stack and heap to prevent overflow
It is a read only memory so that it cannot be changed by accident
Initialize Data Segment-
Usually called Data Segment
It contains a static variables and global variables that are initialized by the program
It is a not a read only memory since it can be changed
Uninitialized Data segment-
Also known an bss segment (blog started by symbol)
It contains static and global variables which are initialized to zero or which are not explicitly initialized
Stack-
It contains the local or automatic variables
Even every memory required by the recursive functions also some from the stack memory.
Heap-
Heap memory is the segment where Dynamic memory allocation takes place
Heap area is shared by all the libraires and dynamically loaded modules in the process.
It has a disadvantage that it need to be manually freed thus leads to memory leaks or fault segment
Moreover variables allocated in stack memory are much faster to access than heap memory