1. High address: Stack (stores local variables, function parameters, and other data), grows down (readable and writable and executable)
2. Heap (dynamically allocated memory is used), and grow up (readable, writable, and executable)
3. Data Segment (save global data and static data) (readable and writable cannot be executed)
4. Status address: code segment (save Code) (readable and executable and not writable)
Code segments are stored in program text, so sometimes called text segments. commands in the instruction pointer are obtained from here. This segment can be shared. For example, if you have two VI in Linux to edit the text, the two VI share a code segment, but the data segment is different (this is a bit similar to sharing the same member function for different objects in C ++ classes ).
Data segments are used to store data. They can also be divided into three areas: the data zone initialized as non-zero, the BSS, and heap. The initialized non-zero data area generally stores static non-zero data and global non-zero data. BSS is the abbreviation of block started by symbol. It is originally a term in assembly language. This area stores uninitialized global data and static data. There is also a heap. This region is used for dynamic memory allocation, that is, the memory allocated by using functions such as malloc is in this region. Its address increases upwards.
The last stack segment (note that the stack is a stack, the heap is a stack, Not The Same Thing). The stack is too important. data such as local variables and function parameters are stored here. For example, recursive algorithms are implemented by stacks. Stack addresses increase downward. The details are as follows:
========= High address ======
Program stack segment
Downward Growth
"Empty" ======
Upward growth
Heap
------ Data Segment
BSS
------
Non-zero data
========= Low address ======
======================
Code snippet
======================
Note that the code segments and data segments are clearly separated, but the data segments and stack segments do not exist. In addition, the stack increases downward and the stack increases upwards, therefore, in theory, the heap and stack will "grow together", but the operating system will prevent such errors, so don't worry too much.
From http://www.cnblogs.com/qlee/archive/2011/09/07/2169831.html