Internally, what is stored on the stack and heap?

In C#, Value Types (eg: int, float, etc) are stored on the stack. Method parameters may also be stored on the stack as well. Most everything else, however, is stored on the heap. This includes Lists, objects, etc.

I was wondering, does CPython do the same thing internally? What does it store on the stack, and what does it put on the heap?


All Python objects in the CPython implementation go on the heap. You can read in detail how Python's memory management works here in the 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.

Note that Python itself is just a language, and says nothing about how internals like memory management should work; this is a detail left to implementers.


Python的运行时间只处理对象的引用(全部都在堆中):Python堆栈上的内容(作为操作数和字节码操作的结果)始终是引用 (指向其他地方的值)。

链接地址: http://www.djcxy.com/p/80432.html

上一篇: 通常如何实现堆?

下一篇: 在内部,什么是存储在堆栈和堆?