In C++, the local variables are stored in stack, while the datas created by new operator are stored in heap. So, what about the variables in Python? Where are they stored?
-
Related : stackoverflow.com/questions/14546178/…Ashwini Chaudhary– Ashwini Chaudhary2013-07-20 17:58:39 +00:00Commented Jul 20, 2013 at 17:58
-
Related : stackoverflow.com/questions/2353552/…Ashwini Chaudhary– Ashwini Chaudhary2013-07-20 18:00:04 +00:00Commented Jul 20, 2013 at 18:00
Add a comment
|
1 Answer
Copying from Python documentation:
Memory management in Python involves a private heap containing all Python objects and data structures. The management of this private heap is ensured internally by the Python memory manager. The Python memory manager has different components which deal with various dynamic storage management aspects, like sharing, segmentation, preallocation or caching.
3 Comments
Marcin
This is misleading - although from the perspective of the C code, the python stuff is generally on the heap, python still has it's own call stack.
dkar
@Marcin: This is from the official Python documentation and the same answer is given to other linked questions. The only thing to add here is that this is specific to CPython, which anyway is the most widely used implementation of Python.
Marcin
Just because it's from an official document, it doesn't mean that it applies to this question. First of all, this question is about variables; secondly the document is about what the CPython interpreter looks like when programming in C.