<分区> 分区>
当我学习 C/C++ 时,我不仅学习了语言的语法和语言结构的语义,还学习了计算机如何执行程序。我学到了这样的东西:
All local variables are declared in a stack frame, which is allocated each time the function is called. These frames are laid out on the call stack one right after the other, and they're 'unwound' when the function returns, thus quickly and efficiently 'destroying' the local variables for that function
反过来,这帮助我弄清楚为什么获取局部变量的地址并将其返回给调用函数是个坏主意。换句话说,了解 C/C++ 的内存模型和代码执行环境有助于加深对如何编写正确程序的理解。
另一个例子:malloc/new 在“堆”(而不是堆栈)中分配对象,这都解释了为什么它们存在于分配它们的函数的末尾之外。此外,知道这些函数/关键字返回对象所在的内存地址有助于我理解链表之类的东西是如何工作的。 (以及如何确定我是否需要另一个 * 或 ->。)
所以现在我正在学习 Python,并且我正在寻找关于 Python 程序如何管理其内存和执行环境的简明、清晰但透彻的解释。
在线搜索并不是特别有成果 - 我可能使用了错误的搜索词,但总的来说似乎很少。
我已经查看了 https://docs.python.org/并发现它是语法和语义的极好资源(“如果你输入 X,那么 Y 就会发生”),但它并没有真正描述计算机在“幕后”做什么。
我在 Stack Overflow 上找到了几篇帖子(例如 this、this 和 this),但这些帖子似乎都针对特定情况。
有谁知道真正解释 Python 在幕后所做的事情的资源吗?
EDIT: I'm getting feedback from StackOverflow that this question may be a duplicate. The other question asks 'how does a .PY file get compiled (to bytecode) and then executed by the VM?' What I'm asking here is 'is there a page that explains how Python lays variables, objects, functions, etc out in memory AND explains how that's all used to actually run Python programs' (Sub-question: Is this an appropriate way to address the concern about a duplicate question? Would it be better to put this in a comment?)
