Вопрос

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?

Это было полезно?

Решение

This is due to the frozenset constructor logic in C, but it's indeed possibly worth a CPython bug report.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top