■ .text — the actual executable code
■ .rodata — any read only data used in the execution of the code
■ .rwdata — where read/write variables and pointers are stored
■ .heap — where dynamically allocated memory is located /堆 向大地址方向生长
■ .stack — where function call parameters and other temporary data is stored /栈 向小地址方向生长
栈增长和大端/小端问题是和CPU相关的两个问题。在内存管理中,与栈对应是堆。对于堆来讲,生长方向是向上的,也就是向着内存地址增加的方向;对于栈来讲,它的生长方式是向下的,是向着内存地址减小的方向增长。在内存中,“堆”和“栈”共用全部的自由空间,只不过各自的起始地址和增长方向不同,它们之间并没有一个固定的界限,如果在运行时,“堆”和 “栈”增长到发生了相互覆盖时,称为“栈堆冲突”,系统肯定垮台。在常见的x86中内存中栈的增长方向就是从高地址向低地址增长。我们可以通过一些代码来判断栈的增长方向:#include<stdio.h>
static int stack_dir;
static void find_stack_direction (void) {
static char *addr = NULL;
char dummy;
if (addr == NULL)
{
addr = &dummy;
find_stack_direction ();
}
else
if (&dummy > addr)
stack_dir = 1;
else
stack_dir = -1;
}
int main(void)
{
find_stack_direction();