第四章 Python中的List对象
- 章节名:第四章 Python中的List对象
列表对象的定义: typedef struct { PyObject_VAR_HEAD /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ PyObject **ob_item; /* ob_item contains space for 'allocated' elements. The number * currently in use is ob_size. * Invariants: * 0 <= ob_size <= allocated * len(list) == ob_size * ob_item == NULL implies ob_size == allocated == 0 * list.sort() temporarily sets allocated to -1 to detect mutations. * * Items must normally not be NULL, except during construction when * the list is not yet visible outside the function that builds it. */ Py_ssize_t allocated; } PyListObject; 通过PyList_New(size)来创建PyListObject 有一个free_list来缓存申请的PyListObject 当调用list_dealloc销毁PyListObject时,把对象的元素清空。同时放到free_list中。 即free_list不像整数类型的free_list会在python初始化时就申请空间,而只是回收已申请的空间
goorockey对本书的所有笔记 · · · · · ·
-
第二章 Python中的整数对象
对象结构:PyIntObject typedef struct { PyObject_HEAD long ob_ival; } PyIntObject; 整数类...
-
第三章 Python中的字符串对象
字符对象的定义: typedef struct { PyObject_VAR_HEAD long ob_shash; int ob_sstate; char ...
-
第四章 Python中的List对象
-
第五章 Python中的dict对象
由于python很多地方都用字典类型实现,对速度要求高,所以: 1、python的字典通过散列表实现...
-
Python代码对象
一个Code Block算一个名字空间,一个Code Block指一个名字 空间或者作用域 一个名字空间对应...
说明 · · · · · ·
表示其中内容是对原文的摘抄