什么是自由列表(PyDict_ClearFreeList引用的)?

2024-09-26 18:13:19 发布

您现在位置:Python中文网/ 问答频道 /正文

Python字典有一个名为^{}的C API函数。但是docstring相当稀疏:

int PyDict_ClearFreeList()

Clear the free list. Return the total number of freed items.

New in version 3.3.

这个函数没有参数,所以它(可能)与任何特定的字典无关。在

它返回一个int。这看起来很奇怪,因为这表明它引用了某种C状态,因为python“类”总是有一个Py_ssize_t大小。在

那么这个“免费名单”到底是什么呢?在


Tags: ofthe函数apifreenumberreturn字典
1条回答
网友
1楼 · 发布于 2024-09-26 18:13:19

您是正确的,自由列表与任何特定的字典无关;事实上,它适用于许多数据类型(例如^{})。在

空闲列表是Python保存它可以放置东西的空闲位置的列表,即包含不再使用的对象的内存,但是它还没有释放回全局Python内存池或系统。在

this useful Theano tutorial

To speed-up memory allocation (and reuse) Python uses a number of lists for small objects. Each list will contain objects of similar size: there will be a list for objects 1 to 8 bytes in size, one for 9 to 16, etc. When a small object needs to be created, either we reuse a free block in the list, or we allocate a new one.

相关问题 更多 >

    热门问题