Examples of 'Python Programming on Win32'
Tim Roberts
timr at probo.com
Fri May 5 07:42:06 CEST 2000
Peter Schneider-Kamp <petersc at stud.ntnu.no> wrote:
>
>I seem to have some nice memory leaks in my modular
>arithmetic module.
I would disagree with this statement. It's not that you have a memory
LEAK, it's that your algorithm is a memory HOG. Consider:
>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]))
You said "u is a list of 10000 integers". Thus, R is 10000. By the time
we get to this point in the program, "c" is a 2-dimensional array
containing 100,000,000 elements, each of which is an integer. I'm not yet
savvy enough to know the internal representation of Python data types, but
this has to be at LEAST a double word, in which case "c" will be at LEAST
400 megabytes.
>.... the system has 224 MB of ram (96 + 128 swap)...
...which is at best half the size it needs to be.
>Would using JPython fix this problem?
No. Even if you ported this algorithm to C (or assembler, for that
matter), it would still need half a gigabyte of RAM. You need a different
algorithm. It's just that simple.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list