首页 > 编程语言 >《CPython Internals》阅读笔记:p177-p220

《CPython Internals》阅读笔记:p177-p220

时间:2025-01-16 22:56:25浏览次数:1  
标签:CPython GNU p220 Internals when allocation memory variable allocated

《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)

标签:CPython,GNU,p220,Internals,when,allocation,memory,variable,allocated
From: https://www.cnblogs.com/codists/p/18675881

相关文章

  • 《CPython Internals》阅读笔记:p152-p176
    《CPythonInternals》学习第10天,p152-p176总结,总计25页。一、技术总结1.addinganitemtoalistmy_list=[]my_list.append(obj)上面的代码涉及两个指令:LOAD_FAST,LIST_APPEND。整章看下来这有这点算是可以记的了,其它的只感觉作者在零零碎碎的罗列内容。二、英语......
  • 《CPython Internals》阅读笔记:p151-p151
    《CPythonInternals》学习第9天,p151-p1510总结,总计1页。一、技术总结无。二、英语总结(生词:1)1.marshal(1)marshalingMarshallingormarshaling(USspelling)istheprocessoftransformingthememoryrepresentationofanobjectintoadataformsuitablefo......
  • 《CPython Internals》阅读笔记:p76-p95
    《CPythonInternals》学习第5天,p76-p95总结,总计20页。一、技术总结无。二、英语总结(生词:1)1.checkvi/vt.toexamsthtoensureitiscorrect,true,oringoodcondition.示例:(1)AfterI'dfinishedthetest,Icheckedmyanswersformistakes.这种用法比......
  • 《CPython Internals》阅读笔记:p43-p60
    《CPythonInternals》学习第3天,p43-p60总结,总计18页。一、技术总结1.编译所需要的packagesudoaptinstall-ybuild-essentiallibssl-devzlib1g-devlibncurses5-dev\libncursesw5-devlibreadline-devlibsqlite3-devlibgdbm-dev\libdb5.3-devlibbz2-devlib......
  • 深入Python胶水语言的本质:从CPython到各类扩展机制
    在开始深入讲解Python如何作为胶水语言之前,我们需要先了解Python语言本身的实现机制。这对于理解Python如何与C语言交互至关重要。CPython:Python的默认实现当我们谈论Python时,实际上通常指的是CPython,即用C语言实现的Python解释器。这是Python的参考实现,也是最广泛使用的Python......
  • CPython调试和性能分析
    cpython解释器在源码ceval.c的_PyEval_EvalFrameDefault函数有一个大的switch(opcdoe)就是字节码解释器的主要部分,示例代码如下:switch(opcode){caseLOAD_FAST://实现LOAD_FAST操作的代码break;caseSTORE_FAST://实现STORE_F......
  • P2201 数列编辑器(对顶栈)
    include<bits/stdc++.h>usingnamespacestd;definexfirstdefineysecondtypedefpair<int,int>PII;typedeflonglongll;typedefunsignedlonglongull;typedefunsignedintuint;typedefvectorVS;typedefvectorVI;typedefvector<vect......
  • 让 cpython 优化恒定条件
    我正在用Python编写需要尽可能高效运行的代码,但有时我需要深入挖掘调试语句。不要注释这些输入或输出(或者使用外部预处理器来处理代码,就像这里建议的那样Python相当于#ifdefDEBUG或这里如何在python中实现“#ifdef”?|||)我想在模块的开头定义一个变量......
  • 智能高效:SP22010-6电力模块助力电力行业升级
    SP22010-6高频电力模块:电力行业的革新者在电力技术日新月异的今天,SP22010-6高频电力模块凭借其卓越的性能和先进的技术,成为电力行业的新星。这款模块采用了高频技术,大大提高了电能的转换效率,为各种电力应用提供了更稳定、更高效的能源支持。SP22010-6不仅具备高效能,而且设计......
  • Sysinternals中有用的命令行工具
    Sysinternals(en)在1996年由MarkRussinovich创建,有一堆绿色小巧强大的工具组成,可帮助你管理、排查Windows和Linux系统与应用程序的问题并进行诊断。 注:64位进程建议用64位Sysinternals工具,32进程建议用32位Sysinternals工具 handle.exe(handle64.exe)handle64.exe -accept......