string copying

Peter Hansen peter at engcorp.com
Sun Mar 31 01:24:54 EST 2002


phil hunt wrote:
> 
> On Fri, 29 Mar 2002 18:16:27 -0500, Peter Hansen <peter at engcorp.com> wrote:
> >The only one I've been able to think of is the surprisingly
> >common situation of trying to consume vast quantities of memory
> >quickly by something like:
> >
> >a = [0] * 1000000
> >for i in xrange(1000000):
> >    a[i] = 'bigstringsuckinguplotsofmemory'
> 
> Simpler is range(1000000)

Yeah, I know.  I think you and Aahz missed my (admittedly puny)
point, which was to hypothesize _at least one case_ where it
was conceivably desirable by someone to try to copy a string.

I've seen the above, without 'bigstring' + str(i) and without
any attempt at simplification, posted several times by newbies
attempting for various reasons to consume a lot of memory.
Maybe they just wanted to consume it gradually rather than
all in one big piece.

The fact that this approach is entirely the wrong one doesn't
change the fact that some people think they want it.  Which
was all I was trying to say.  I'll go away again now. :)

-Peter



More information about the Python-list mailing list