Memory Segments in C
Memory Segments in C, There are different types of memory segments in the userspace.
1. Text segment:
text segment will store all the instructions which are part of the program.
2. Stack:
stack segment is used to store all local variables and is used for passing arguments to the functions along with the return address of the instruction which is to be executed after the function call over. The stack and heap grow in opposite directions. If you want to see the stack memory allocation on the process run the below command.
cat /proc/127/smaps (127 is process id)
3. Initialized Data:
Memory Segments in C, Initialized data stores all global, static, and const that is initialized beforehand. All global, static, and const variables memory allocated at compile time.
See the below-relocated file, x and y variables showed .data, and z variable showed .rodata (read-only data).
4. Uninitialized Data or BSS segment:
uninitialized data stores global and static that are uninitialized beforehand.
See the below-relocated file memory.o, x, and y variables showed .bss
5. Heap:
Heap memory uses to store the dynamic memory allocation. If you want to see the heap memory allocation on the process run the below command.
cat /proc/127/smaps ( 127 is process id)
Recent Comments