[Edu-sig] MemoryError?

David MacQuigg macquigg at ece.arizona.edu
Sun Apr 22 01:02:00 CEST 2012


No problem with Python 2.7.3 on a MacBookPro with 2GB memory and a light load of other programs.  Could it be dependent on how much memory you have available?  

There might be slight differences in the memory consumption in computing the two different forms.  I would guess the second form might take less memory because it allocates exactly what it needs, not some larger amount based on a dynamic allocation algorithm for expanding lists.




>________________________________
> From: Litvin <litvin at skylit.com>
>To: edu-sig at python.org 
>Sent: Saturday, April 21, 2012 1:50 PM
>Subject: [Edu-sig] MemoryError?
> 
>
>Can someone please explain why 
>
>n = 50000000
>lst = [i for i in range(n)] # or xrange(n) in Python 2
>
>crashes with MemoryError on a 32-bit system, while
>
>n = 50000000
>lst = n*[0]
>for i in range(n):  # or xrange(n) in Python 2
>    lst[i] = i
>
>works?
>
>Thanks,
>
>Gary Litvin
>www.skylit.com
>
>
>_______________________________________________
>Edu-sig mailing list
>Edu-sig at python.org
>http://mail.python.org/mailman/listinfo/edu-sig
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20120421/69ec201a/attachment.html>


More information about the Edu-sig mailing list