《CPython Internals》閱讀筆記:p177-p220
《CPython Internals》學(xué)習(xí)第 11天,p177-p220 總結(jié),總計(jì) 44 頁(yè)。
一、技術(shù)總結(jié)
1.memory allocation in C
(1)static memeory allocation
Memory requirements are calculated at compile time and allocated by the executable when it starts.
(2)automatic memeory allocation
Memory requirements for a scope are allocated within the call stack when a frame is entered and are freed once the frame is terminated.
(3)dynamic memeory allocation
Memory can be requested and allocated dynamically at runtime by calls to the memory allocation API。
上面這幾個(gè)定義摘自第 178 頁(yè)。我不得不再次吐槽:既然是分類(lèi),那么分類(lèi)的依據(jù)是什么?很遺憾,作者沒(méi)有說(shuō)。介于此,補(bǔ)充一個(gè)GNU的文檔說(shuō)明,個(gè)人覺(jué)得GNU的說(shuō)明更清楚:
The C language supports two kinds of memory allocation through the variables in C programs:
● Static allocation is what happens when you declare a static or global variable. Each static or global variable defines one block of space, of a fixed size. The space is allocated once, when your program is started (part of the exec operation), and is never freed.
● Automatic allocation happens when you declare an automatic variable, such as a function argument or a local variable. The space for an automatic variable is allocated when the compound statement containing the declaration is entered, and is freed when that compound statement is exited.In GNU C, the size of the automatic storage can be an expression that varies. In other C implementations, it must be a constant.
A third important kind of memory allocation, dynamic allocation, is not supported by C variables but is available via GNU C Library functions.
Dynamic memory allocation is a technique in which programs determine as they are running where to store some information. You need dynamic allocation when the amount of memory you need, or how long you continue to need it, depends on factors that are not known before the program runs.
For example, you may need a block to store a line read from an input file; since there is no limit to how long a line can be, you must allocate the memory dynamically and make it dynamically larger as you read more of the line.
從GNU的文檔中我們不難看出:首先根據(jù)是否需要手動(dòng)可
二、英語(yǔ)總結(jié)(生詞:0)
無(wú)。
關(guān)于英語(yǔ)的注解同步更新匯總到 https://github.com/codists/English-In-CS-Books 倉(cāng)庫(kù)。
三、其它
今天沒(méi)有什么想說(shuō)的。
四、參考資料
1. 編程
(1) Anthony Shaw,《CPython Internals》:https://book.douban.com/subject/35405785/
2. 英語(yǔ)
(1) Etymology Dictionary:https://www.etymonline.com
(2) Cambridge Dictionary:https://dictionary.cambridge.org

歡迎搜索及關(guān)注:編程人(a_codists)
浙公網(wǎng)安備 33010602011771號(hào)