CPython-内部,堆栈和堆中存储了什么? [英] CPython - Internally, what is stored on the stack and heap?

查看:212
本文介绍了CPython-内部,堆栈和堆中存储了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,值类型(例如:int,float等)存储在堆栈中.方法参数也可以存储在堆栈中.但是,大多数其他所有内容都存储在堆中.这包括列表,对象等.

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.

我想知道,CPython是否在内部做同样的事情?它存储在堆栈中什么,放在堆中什么?

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?

推荐答案

CPython实现中的所有Python对象都在堆上.您可以在 此处 中详细了解Python的内存管理工作原理. >在文档中:

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:

Python中的内存管理涉及一个私有堆,其中包含所有Python对象和数据结构..此私有堆的管理由Python内存管理器在内部确保. Python内存管理器具有不同的组件,这些组件处理各种动态存储管理方面的问题,例如共享,分段,预分配或缓存.

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.

请注意,Python本身只是一种语言,并且没有说明诸如内存管理之类的内部组件应如何工作;这是留给实施者的细节.

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.

这篇关于CPython-内部,堆栈和堆中存储了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆