Comment 13 for bug 624310

Revision history for this message
Seif Lotfy (seif) wrote :

I had a brief discussion with the guys on #python
---
<seiflotfy> can u explain to me why inheriting from object with __slots__ uses less memory than inheriting from list? make it for dummies so i can explain it to my team

<verte> seiflotfy: do you know what a struct looks like in memory?

<seiflotfy> verte, nope

<verte> seiflotfy: __slots__ is exactly that. on some implementations of python, the object literally has one pointer for each field. there's no dict hanging about to store attributes.

<seiflotfy> so the statement is true then ?

<nedbat> seiflotfy: the statement about __slots__ reducing memory? Yes, that was a major goal of __slots__.

<verte> seiflotfy: oh, yes. if you need methods on what would otherwise be a tuple, and you expect to have lots of those objects, __slots__ may be a good idea.