[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Q on document Unifying types and classes in Python
From:       martin () v ! loewis ! de (Martin v !  =?iso-8859-15?q?L=F6wis?=)
Date:       2003-06-30 3:49:50
[Download RAW message or body]

rimbalaya@yahoo.com (Rim) writes:

> "This is not always what you want; in particular, using a separate
> dictionary to hold a single instance variable doubles the memory used
> by a defaultdict instance compared to using a regular dictionary!"
> 
> I don't understand what is the separate dictionary Guido is talking
> about.

The defaultdict *is-a* dictionary in itself; it also *has-a*
dictionary: the dictionary of instance variables (a.__dict__).  The
second one is a separate dictionary, one that doesn't exist for a
dict() object.

> I also don't understand how one additional entry (the 'default'
> entry) in the dictionary doubles the dictionary size... except when
> the dictionary has only one element, then of course, adding another
> element will cause it double in number of elements.

The fixed overhead doubles. Since dictionaries start off with 8 slots,
both the 'a' dictionary itself, and 'a.__dict__' still consume this
initial size only, doubling memory consumption. As 'a' proper fills
up, memory consumption won't be twice as large anymore compared to the
'proper dictionary' case.

HTH,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic