string copying

Tim Peters tim.one at comcast.net
Fri Mar 29 19:22:45 EST 2002


[Peter Hansen]
> 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'

Hmm.  A much easier way to consume vast quantities of memory quickly is to
skip the for-loop and just increase the multiplier on the first line.  If
you're on a 32-bit machine, and want to consume N bytes, use N/4 as the
multiplier.





More information about the Python-list mailing list