APUE Chapter 7(3) – Memory layout of a C program

一个C语言的可执行程序(a.out)通常被分成以下几个部分:

   · Text segment: 即汇编中的.text segemnt。machine instruction, sharable, only one copy in memory, read-only

   · Initialized data: 即汇编中的.data segment。是已经初始化的数据。是出现在所有的程序之外的变量(全局变量)。

   · Uninitialzed data: 即汇编中的.bss segment(“block started by symbol”)。这些变量也是出现在所有程序之外(全局变量),并且由kernel初始化为0或者NULL。

   · Stack: 存放automatic variables(local variables). Store information to call a (new) function.

   · Heap: dynamic memory allocation.

     image

     在我们磁盘中存储的C语言可执行文件(a.out)中,只保存着text 和 data两个segment。(当然还有一些其他的信息,比如链接信息等等。这些信息在程序执行时不会被放到内存中)。

原文地址:https://www.cnblogs.com/wangshuo/p/2039003.html