getting used/available memory
Peter Schneider-Kamp
petersc at stud.ntnu.no
Wed May 3 05:37:18 EDT 2000
Hei!
I seem to have some nice memory leaks in my modular
arithmetic module. To find out where the memory goes
I'd like to find out how much memory is occupied/free
at a given time. I did not find anything in sys or os
on first sight. Where do I have to go?
I am using python 1.5.2 on linux. The routine in
question is:
def tolong(u,m):
R = len(u)
v = copy.copy(u)
n = map(long,m)
c = []
for j in range(R):
if (j % 100)==0:
print "o"
c.append([])
for k in range(R):
c[j].append(mulinv(m[j],m[k]))
for j in range(R-1):
for k in range(j+1,R):
v[k] = (v[k]-v[j])*c[j][k] % m[k]
w = v[0]
for j in range(R-1):
w = w + v[j+1] * n[0]
n[0] = n.pop(0) * n[0]
return w
where m is a list of 10000 relative prime integers
below 2**31 and u is a list of 10000 integers which
are as well below 2**31. the system has 224 MB of
ram (96 + 128 swap) and after about 1000 iterations
the system runs out of memory and I have to
emergency sync and reboot.
Would using JPython fix this problem?
thanks for any advice
Peter
P.S.: The function mulinv calculates the multiplicative
inverse of a relative to b using the forward
version of the extended euclidean algorithm.
as it is used in the inner loop the memory leak
might as well be there:
def mulinv(a,b):
s = [1,0]
m = b
while b > 0:
q, r = divmod(a,b)
s.append(s.pop(0)-q*s[0]);
a = b
b = r
return s[0] % m
--
Peter Schneider-Kamp ++47-7388-7331
Herman Krags veg 51-11 mailto:peter at schneider-kamp.de
N-7050 Trondheim http://schneider-kamp.de
More information about the Python-list
mailing list