Don't use __slots__ (was Re: Why custom objects take so much memory?)

Delaney, Timothy (Tim) tdelaney at avaya.com
Tue Dec 18 17:23:27 EST 2007


Aahz wrote:

> In article <mailman.2538.1198008758.13605.python-list at python.org>,
> Chris Mellon <arkanes at gmail.com> wrote:
>> 
>> You can reduce the size of new-style classes (inherit from object) by
>> quite a bit if you use __slots__ to eliminate the class dictionary.
> 
> You can also reduce your functionality quite a bit by using __slots__.
> Someday I'll have time to write up a proper page about why you
> shouldn't use __slots__....

Although admittedly this *is* one of the cases where __slots__ is being
suggested for it's intended use - where memory issues require smaller
objects.

Of course, a better result can probably be achieved by using a different
algorithm or technology (database?).

Tim Delaney



More information about the Python-list mailing list