简体   繁体   中英

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 :

>>> 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? Or is this just a quirk of how Pympler approximates the amount of memory occupied by a variable in Python?

这是由于C中的冻结构造函数逻辑,但它确实值得CPython错误报告。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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