2016年12月2日 星期五

[C51/ARM] 記憶體配置:heap/stack/bss/data/text

此介紹是給在Keil C編譯器上使用8051(C51)和ARM.
(下列介紹由記憶體位置高排到低)

●heap
通常是給動態記憶配置(dynamic memory allocation)使用,需要programmer自己申請.

●stack
區域變數(local variable)
函式參數(function/method parameter)
函數的返回位址(function/method return address)
Keil官方手冊: 3.4 Stack use in C and C++

●bss (uninitialized data)

●data (initialized data)

●text code (text segment)
CPU instructions stored in here.


Example:
const int a = 1;  //stored in data
int b = 1;  //stored in data
int c; //stored in bss

int main(void)
{
    const static int w = 1; //stored in data
    static int x = 1; //stored in data
    static int y; //stored in bss
    int z = 1; //stored in stack  
    int *buffer = (char*) malloc(sizeof(char) * 10); //stored in heap  
}




#記憶體配置#Memory Layout of C#heap#stack#bss#data#text

沒有留言:

張貼留言