Python如何在内部存储列表? [英] How does Python store lists internally?
问题描述
或者解释器根据长度等猜测每个实例的正确结构。
如果问题是依赖于实现的,那么经典的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屋!