Python列表内存存储 [英] Python List Memory Storage

查看:94
本文介绍了Python列表内存存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解Python列表本质上是C数组,它们分配了特定的顺序内存块;但是,这些内存是实际存储列表中的数据还是仅指向存储实际数据的内存中的另一个位置?

I understand that Python lists are essentially C arrays, that they allocate a specific block of sequential memory; but, do these pieces of memory actually store the data that is in the list or do they simply point to another location in memory where the actual data is stored?

这是否取决于列表中存储的对象的大小?因为您可以轻松地顺序存储一个整数列表,但是要动态地存储包括自定义对象在内的各种对象将变得更加困难.

Does it perhaps depend on the size of the object stored in the list? As you could easily store a list of ints sequentially but it would be harder to dynamically store a variety of objects including self-defined objects.

推荐答案

否,python列表存储对对象的引用(指针")

No, python lists store references ("pointers") to the objects

性能说明#

列表对象由两个内部部分组成;一个对象标头,以及 一个单独分配的对象引用数组.后者是 重新分配.

The list object consists of two internal parts; one object header, and one separately allocated array of object references. The latter is reallocated as necessary.

这篇关于Python列表内存存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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