Hi Antoine,
On Sat, Mar 30, 2013 at 10:37 PM, Antoine Pitrou <[email protected]> wrote:
> On Sat, 30 Mar 2013 17:31:26 -0400
> Micha Gorelick <[email protected]> wrote:
>> I was taking a look at dictobject.c and realized that the logic
>> controlling whether a resizedict will occur in
>> dict_set_item_by_hash_or_entry disallows for the shrinking of a
>> dictionary.
It doesn't disallow shrinking. If you take a dictionary of size 1000,
remove of its elements, and continue to use it (write and delete more
items) for long enough, then eventually it is shrinked. It just takes
a while because it needs to fill 2/3 of the slots of the big table
with "deleted" markers before it happens.
Python 3.3.0b1 (default:07ddf5ecaafa, Aug 12 2012, 17:47:28)
[GCC 3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> d = {i:i for i in range(1000)}
>>> sys.getsizeof(d)
24624
>>> for i in range(1000): del d[i]
...
>>> sys.getsizeof(d)
24624
>>> for j in range(1001, 2000):
... d[j] = 0; del d[j]
...
>>> sys.getsizeof(d)
144
>>>
A bientôt,
Armin.
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com