[Tutor] Memory Problem [for loops, range(), and psyco]
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Sat Jul 5 17:18:02 2003
On Fri, 4 Jul 2003, Magnus [iso-8859-1] Lyck=E5 wrote:
> At 08:02 2003-07-04 +0200, Abel Daniel wrote:
> >Magnus Lyck? wrote:
> > > If you just use xrange() instead of range(), you won't create any
> > > list, but I don't know if Python will actually release the memory
> > > used for integers, since they are interned. (That integers are
> > > interned means that if you use 42 in several different places in
> > > your code, it will always use the same integer object.)
> >Isn't this only done for small ( < 100) integers?
>
> Oh, I didn't know that. Thanks! Is that a recent change? I seem to
> remember that construction of big ranges was a problem, since the
> integers weren't garbage collected.
Hi Magnus,
The problem with big ranges had to do with the construction of the range
list itself, and not as much with the integers.
I believe that 'psyco', the Specializing Python Compiler, does optimize
range()s away if a program uses them as loop counters. Let me see...
Ok, I found that reference:
http://psyco.sourceforge.net/psycoguide/node27.html
Footnote 8 says that psyco will transform 'for i in range(42)' into a
standard C 'for(i=3D0;i<42;i++)' loop, and that's really cool.
Dorsey's application sounds really computational, so Dorsey may want to
look into psyco and see if it's useful. Psyco can be found here:
http://psyco.sourceforge.net