vendredi 15 juillet 2016

Huge memory consumption while trying to run this code

While trying to run this code:

l = 1000000
w = [1, 1]
for i in range(2, l):
    w.append(w[-1] + w[-2])

computer hangs on and Blue screen of death appears. The only info which I get is about MEMORY MANAGEMENT. Problem occurs in version 2.7 of Python and 3.4 as well.

Code works good for l = 100000.

Can someone explain me exactly why? I am using Windows 10 64-bit, Python 2.7.8 64-bit from Active Python.

EDIT:

Here is R code which works well:

len <- 1000000
fibvals <- numeric(len)
fibvals[1] <- 1
fibvals[2] <- 1
for (i in 3:len) { 
   fibvals[i] <- fibvals[i-1]+fibvals[i-2]
} 

Aucun commentaire:

Enregistrer un commentaire