[triangle-zpug] why is this using a lot of memory?

Chris Church flyingfred0+trizpug at gmail.com
Tue Mar 25 15:57:54 UTC 2008

Using range() creates a list containing 10,000,000 integers, which is why it
requires most of your memory.  You probably want to use xrange() instead,
which creates an iterator that gives you one integer at a time from your

On Tue, Mar 25, 2008 at 11:23 AM, Joseph Mack NA3T <jmack at wm7d.net> wrote:

> intervals=10000000 #some large number
> height=0
> for x in range(0, intervals):
>        height+=x
> (I get the same result whether running interactive or from a
> file with the above code)
> For a sufficiently large value of "intervals" the program
> exits immediately with a MemoryError. For slightly smaller
> values, the program takes up most of the memory of the
> machine. I would have thought that you'd only be allocating
> a couple of variables. What am I missing? Am I allocating an
> "intervals" number of something, rather than a single
> variable with a large value?
> thanks Joe
> --
> Joseph Mack NA3T EME(B,D), FM05lw North Carolina
> jmack (at) wm7d (dot) net - azimuthal equidistant map
> generator at http://www.wm7d.net/azproj.shtml
> Homepage http://www.austintek.com/ It's GNU/Linux!
> _______________________________________________
> triangle-zpug mailing list
> triangle-zpug at starship.python.net
> http://starship.python.net/mailman/listinfo/triangle-zpug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://starship.python.net/pipermail/triangle-zpug/attachments/20080325/698c09d1/attachment.htm 

More information about the triangle-zpug mailing list