pickle: huge memory consumption *during* pickling

Jean Brouwers mrjean1ATcomcastDOTnet at no.spam.net
Fri Nov 12 14:52:14 EST 2004


Using __slots__ will reduce memory usage quite a bit.  Like the OP, we
found significant improvements in both memory usage and speed, more
details here

<http://mail.python.org/pipermail/python-list/2004-May/220513.html>

But __slots__ do have restictions, see

<http://docs.python.org/ref/slots.html>

Also, it is unclear whether SWIG can generate a class with __slots__ at
all. 

/Jean Brouwers
 ProphICy Semiconductor, Inc.



In article <cn1rt4$agn$1 at fuerst.cs.uni-magdeburg.de>, Hans Georg
Krauthaeuser <hgk at et.uni-magdeburg.de> wrote:

> Nick Craig-Wood wrote:
> > ....
> > You've probably got lots of instances of a single class...  We managed
> 
> You are right. My data are class objects taken from a c++ class (via swig).
> 
> > to 1/3 the memory requirments in a similar situation by using new
> > style classes (inherit from object) and defining __slots__ for just a
> > single class!
> 
> Interesting, I didn't noticed __slots__ before.
> 
> In the swig-wrapper I found that my object are inherited from _object 
> and that is
> 
> import types
> try:
>      _object = types.ObjectType
>      _newclass = 1
> except AttributeError:
>      class _object : pass
>      _newclass = 0
> del types
> 
> So, this are new style classes.
> 
> Now, I have to see how to get swig to generate __slots__ ...
> 
> Thanks,
> 
> Hans Georg



More information about the Python-list mailing list