《CPython Internals》阅读笔记:p177-p220
《CPython Internals》学习第 11天,p177-p220 总结,总计 44 页。
一、技术总结
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。
上面这几个定义摘自第 178 页。我不得不再次吐槽:既然是分类,那么分类的依据是什么?很遗憾,作者没有说。介于此,补充一个GNU的文档说明,个人觉得GNU的说明更清楚:
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的文档中我们不难看出:首先根据是否需要手动可
二、英语总结(生词:0)
无。
关于英语的注解同步更新汇总到 https://github.com/codists/English-In-CS-Books 仓库。
三、其它
今天没有什么想说的。
四、参考资料
1. 编程
(1) Anthony Shaw,《CPython Internals》:https://book.douban.com/subject/35405785/
2. 英语
(1) Etymology Dictionary:https://www.etymonline.com
(2) Cambridge Dictionary:https://dictionary.cambridge.org
欢迎搜索及关注:编程人(a_codists)