an intern-like memory saver

Niels Diepeveen niels at endea.demon.nl
Mon Apr 17 15:09:22 CEST 2000


sjmachin at lexicon.net schreef:
> 
> I tried "intern" and read the source code for it. Speed is not a
> consideration until I run out of real memory and start swapping to
> disk. My objective is to reduce memory usage so that that doesn't
> happen. "intern" has its *own* hidden dictionary; if I use it, it may
> even *increase* my memory usage. 

If the number of distinct strings weren't large, that would not be a
problem, but if it is, it is.

> I already have my own dictionary with
> all those strings as keys, so I save the overhead part of the intern
> dictionary. For what it's worth my key_ref method works with any
> objects that can be dictionary keys, not just strings. What are the
> other ways you say one can do very much the same thing in Python?

Variations on the same theme. All of them will use more memory than what
you were proposing.

-- 
Niels Diepeveen
Endea automatisering




More information about the Python-list mailing list