about presicion

mensanator at aol.com mensanator at aol.com
Wed Sep 1 13:00:40 EDT 2004


Alex Martelli wrote:
> mensanator at aol.com <mensanator at aol.com> wrote:
>
> > > > Were you aware that there is apparently a memory leak in the
> > > > gmpy.divm() function? Calling it several million time caused my
> > > > computer to run out of virtual memeory. Luckily, I was able to
> > > > work around it using the gmpy.invert() which didn't consume any
> > > > memory regardless of how many times it was called.
> > >
> > > No, I was not aware of that -- I'll look into it, thanks.
>
> I'm still not aware of any bug in gmpy because I can't reproduce your
> observation (on MacOSX 10.3.5, Python 2.3).  Try this script...:
>
> import gmpy
>
> tot = 0
> while True:
>     n = input('How many more divm: ')
>     if n<=0: break
>     print '%d more...' % n,
>     for i in xrange(n): gmpy.divm(3,7,9)
>     tot += n
>     print '...total %d' % tot
>
> I've used it to perform millions of divm calls and I monitor its
virtual
> memory usage from the outside, and absolutely no leak shows up.
Maybe
> it's in the Windows version of the underlying GMP library...?  Can
any
> other gmpy user try this out and report...?  Thanks!
>
>
> Alex


I tracked your program with Windows task manager and it show a nice
flat memory useage trace. Memory usage started at 185244K and peaked
at 185366K for 10000000 iterations.

Try using larger numbers:

import gmpy


tot = 0
while True:
n = input('How many more divm: ')
if n<=0: break
print '%d more...' % n,
for i in xrange(n): gmpy.divm(81287570543,8589934592,3486784401)
tot += n
print '...total %d' % tot


"""

memory usage trace rocketed upwards at a 45 degree angle.

C:\Python23\user\the_full_monty>python gmpytest.py
How many more divm: 10000000
10000000 more...Fatal Python error: mp_allocate failure
abnormal program termination

peak Commit Charge (K): 792556

"""




More information about the Python-list mailing list