[英]memory occupied by set vs frozenset in Python 2.7
I was recently comparing the amount of memory occupied by a Python set
to that occupied by a frozenset
using Pympler : 我最近比较了使用Pympler将Python set
占用的内存量与frozenset
set
占用的内存量:
>>> from pympler.asizeof import asizeof
>>> x = range(100)
>>> s = set(x)
>>> f0 = frozenset(x)
>>> f1 = frozenset(s)
>>> asizeof(s)
10824
>>> asizeof(f0)
10824
>>> asizeof(f1)
6728
>>> f0==f1
True
Why would a frozenset
created from a set
occupy a different amount of memory than one created from some other iterable? 为什么从set
创建的frozenset
set
占用的内存量不同于从其他迭代中创建的内存量? Or is this just a quirk of how Pympler approximates the amount of memory occupied by a variable in Python? 或者这只是Pympler如何近似Python中变量占用的内存量的一个怪癖?
这是由于C中的冻结构造函数逻辑,但它确实值得CPython错误报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.