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

Bradley A. Crittenden brad.crittenden at gmail.com
Tue Mar 25 16:55:40 CET 2008


On Mar 25, 2008, at 11:23 , Joseph Mack NA3T wrote:

> intervals=10000000 #some large number
> height=0
> for x in range(0, intervals):
> 	height+=x
>

Joe,

Try changing 'range' to 'xrange'.  The former returns the entire list  
while the latter is an iterator, therefore it doesn't consume much  
memory.

--Brad


> (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





More information about the TriZPUG mailing list