[Baypiggies] identity cache / flywheel design pattern
Monte Davidoff
davidoff56 at alluvialsw.com
Sat Aug 2 22:15:09 CEST 2008
JJ,
Shannon -jj Behrens wrote:
> I'm have a program that intrinsically eats up a ton of memory. I
> often read lines from a file that are the same, so I end up with
> multiple copies of the same data in memory.
It sounds like a job for the "intern" built-in function (from section
2.2, Non-essential Built-in Functions, in the Python Library Reference).
>>> s1 = intern("foo")
>>> s2 = intern(''.join(['f', 'o', 'o']))
>>> s1 == 'foo'
True
>>> s1 == s2
True
>>> s1 is s2
True
>>>
Curious that your signature referred to Lisp, which has used the intern
concept for decades! ;-)
Monte
More information about the Baypiggies
mailing list