Python如何在内部存储列表? [英] How does Python store lists internally?

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

问题描述

python中的列表如何在内部存储?是数组吗?一个链表?还有另外一个问题?



或者解释器根据长度等猜测每个实例的正确结构。



如果问题是依赖于实现的,那么经典的CPython呢?

解决方案



列表实现:python-container-under-hood.ppt

固定长度的指针数组

*当数组增长或缩小时,调用realloc(),如有必要,将所有项目复制到新空间

源代码:
包含/ listobject .h 对象/ listobject.c

btw:这里是视频这里


How are lists in python stored internally? Is it an array? A linked list? Something else?

Or does the interpreter guess at the right structure for each instance based on length, etc.

If the question is implementation dependent, what about the classic CPython?

解决方案

from Core Python Containers: Under the Hood
List Implementation:
Fixed-length array of pointers
* When the array grows or shrinks, calls realloc() and, if necessary, copies all of the items to the new space
source code: Include/listobject.h and Objects/listobject.c
btw: here is the video or here

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

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