Any problems with *lots* of attributes?
Paul Prescod
paul at prescod.net
Thu Feb 5 03:11:41 EST 2004
Frank Millman wrote:
>
> This is exactly my point, but I may be misunderstanding how it works
> internally. If I have a class with 20 attributes, it will have a
> dictionary with 20 entries. If I have hundreds of instances of the
> class, do I end up with hundreds of dictionaries (or the equivalent
> internal structures), and if so, does this not lead to memory bloat?
> If I store the data in a list, there will only be one dictionary entry
> per instance. On the other hand, I suppose there must be some
> reference to each of the elements of each list, so maybe there is an
> equivalent overhead.
20 entries * 100 instances = 2000 entries in 100 dictionaries
20 entries * 100 instances = 2000 list indexes in 100 lists
I really don't expect a big memory difference in normal use. I
personally would not worry about it until I actually experienced a
performance issue. Even before you code your app you know the size of
database you care about: why not simulate it and see how the performance is?
Paul Prescod
More information about the Python-list
mailing list