简体   繁体   English

Python如何在内部存储列表?

[英]How does Python store lists internally?

How are lists in python stored internally? 如何在内部存储python中的列表? 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? 如果问题依赖于实现,那么经典的CPython呢?

from Core Python Containers: Under the Hood 来自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 *当数组增大或缩小时,调用realloc(),并在必要时将所有项复制到新空间
source code: Include/listobject.h and Objects/listobject.c 源代码: Include / listobject.hObjects / listobject.c
btw: here is the video 顺便说一句: 这是视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM