6

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?

Marcin
  • 48,559
  • 18
  • 128
  • 201
injoy
  • 3,993
  • 10
  • 40
  • 69

1 Answers1

6

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.

dkar
  • 2,113
  • 19
  • 29
  • 1
    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. – Marcin Jul 20 '13 at 18:35
  • 2
    @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. – dkar Jul 20 '13 at 19:06
  • 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. – Marcin Jul 20 '13 at 19:25