Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Interning own classes like strings for speed and size?

Reply
Thread Tools

Interning own classes like strings for speed and size?

 
 
Hrvoje Niksic
Guest
Posts: n/a
 
      12-28-2010
Christian Heimes <(E-Mail Removed)> writes:

> Also this code is going to use much more memory than an ordinary tuple
> since every instance of InternedTuple has a __dict__ attribute. This
> code works but I had to move the cache outside the class because of
> __slots__.


Wouldn't it work inside the class as well? __slots__ applies to
instances, not to classes themselves. In Python 3.1:

>>> class Foo(tuple):

.... __slots__ = ()
.... _cache = {}
....
>>> Foo._cache # works as expected

{}
>>> Foo()._cache # and so does this

{}
 
Reply With Quote
 
 
 
 
Hrvoje Niksic
Guest
Posts: n/a
 
      12-29-2010
Christian Heimes <(E-Mail Removed)> writes:

> You are right as long as you don't try to rebind the variable.


And then only if you assign through an instance, which doesn't make
sense for a class-level cache. Assignment like Example2._cache = {}
would work.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String interning in Python 3 - missing or moved? Chris Angelico Python 0 01-24-2012 12:38 AM
Disable automatic interning George Sakkis Python 9 03-23-2009 05:54 PM
OT: Interning one day a week? Nocturnal MCSE 10 10-17-2005 04:06 AM
Re: Python name lookups / Interning strings Terry Hancock Python 0 10-12-2005 01:17 AM
interning strings Mike Thompson Python 7 11-08-2004 08:51 AM



Advertisments