1. 程式設計師的自我修養
Chapter 10 記憶體
Shu-Yu Fu (shuyufu@gmail.com)
2. 本章概述
本章討論程式執行時Stack和heap的配置!
● 藉由觀察stack的變化導出Calling convention,
然後函式如何傳遞返回值!
● 除了比較heap在Linux和Windows上的實作外,
我們還會討論heap管理演算法!
● PS︰記得參考這篇產生你的assembly code+C
code
How to get gcc to interleave assembly output
with original source code
Using GCC to produce readable assembly?
3. 程式的記憶體配置
Flat memory model or linear memory model refers to a memory addressing
paradigm in low-level software design such that the CPU can directly (and sequentially/linearly)
address all of the available memory locations without having to resort to any sort of memory
segmentation or paging schemes.
int *p = (int *)0x12345678;
++*p;
● 記憶體空間"預設"的區域︰
○ 堆疊﹙stack﹚
○ 堆積﹙heap﹚
○ ELF / dynamic libraries / reserved
4. 程式的記憶體配置
Flat memory model or linear memory model refers to a memory addressing
paradigm in low-level software design such that the CPU can directly (and sequentially/linearly)
address all of the available memory locations without having to resort to any sort of memory
segmentation or paging schemes.
int *p = (int *)0x12345678;
++*p;
● 記憶體空間"預設"的區域︰
○ 堆疊﹙stack﹚
○ 堆積﹙heap﹚
○ ELF / dynamic libraries / reserved
18. 呼叫慣例
int foo(int n, float m)
{
int a = 0, b = 0;
...
}
● 先推入n後推入m?
● 呼叫方和被呼叫方對於呼叫的約定
○ 參數的傳遞順序﹙左先?右先?﹚和方式﹙堆疊?暫
存器?﹚
○ 堆疊的維護方式,由呼叫方或被呼叫方維護
○ 名稱修飾﹙name-mangling﹚的策略,對呼叫慣例進
行區分