Quesion about the proper use of __slots__
Peter Otten
__peter__ at web.de
Mon Feb 20 06:44:49 EST 2006
bonono at gmail.com wrote:
>
> Zefria wrote:
>> Well, my computer tends to run at about 497 to 501 out of 504 MB of RAM
>> used once I start up Gnome, XMMS, and a few Firefox tabs, and I'd
>> prefer not to see things slipping into Swap space if I can avoid it,
>> and the fighter data would be only part of a larger program.
>>
>> And as I said, learning how to use __slots__ is important enough to
>> hazard a premature guess this time around. If I mess up, the worst that
>> happens is that I have to write down a new variable name in two places
>> instead of one now.
>
> For this particular setup, I don't think it would be a concern given
> your mentioned size as you are very unlikely to be actively using all
> the apps at the same time and linux is quite efficient in handling it.
>
> However, I don't think attempting to use __slots__ in this case is bad
> either. Afterall, one of the strength of python is allowing you to
> quickly test out different approachs.
Yes, something like
import sys
class Fighter(object):
if "--use-slots" in sys.argv:
__slots__ = [...]
and then comparing
$ python fighters.py
with
$ python fighters.py --use-slots
might be instructive. I don't think the OP will perceive a difference.
> He could be working on a machine with < 1M RAM or some other
> constraints.
I have 256K, by the way.
Peter
More information about the Python-list
mailing list