When I learned C/C++ I not only learned the syntax of the language and the semantics of the language constructs but also how the program was executed by the computer. I learned stuff like:
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
This, in turn, helped me figure out why it's a bad idea to take the address of a local variable & return it to the calling function. In other words, understanding C/C++'s memory model and the environment in which the code executes helps develop a deeper understanding of how to write correct programs.
Another example: malloc/new allocate objects in the 'heap' (and not the stack), which both explains why they live beyond the end of the function that allocated them. Further, knowing that these functions/keywords return the memory address that the object is located at helped me to understand how things like linked lists work. (And how to figure out whether I need another *
or ->
or not.)
So now I'm learning Python and I'm looking for a concise, clear, yet thorough explanation of how Python programs manage their memory and execution environment.
Searching online hasn't been particularly fruitful - I might be using the wrong search terms, but there appears to be very little out there in general.
I've looked through https://docs.python.org/ and found it to be an excellent resource for syntax and semantics ("if you type X, then Y will happen"), but it doesn't really describe what the computer is doing 'under the hood'.
I've found several posts here on Stack Overflow ( such as this, this, and this ) but these all seem to focus on specific situations.
Does anyone know of a resource that actually explains what Python is doing under the hood'?
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?)