Re: memory leak huge number of digits mpz_mul,mpf_sqrt_ui

2021-02-26 Thread Torbjörn Granlund
Are you famiiar with valgrind?  It is a great tool for detecting memory
leaks.  I used it to oonfirm that GMP indeed does not leak for your test
cases.  (You seem to have forgotten to mention the system you used for
these experiments; I used an amd64 cpu running debian.)

Your analysis of what is a memory leak is incorrect.  You might need to
better understand the role of malloc/free (in the C library) and the
underlying system memory handling functions (sbrk/brk/mmap/munmap).  The
former do not necessarily give back its memory to the system.  That's
not a memory leak by normal definitions.  Or at least, an application
cannot affect this "leak".

Again: No GMP bug.

The GMP lists are not the right place for discussions about how malloc
interfaces to the kernel.  But I am sure there are great explanations
which you will be able to find on the Net.


-- 
Torbjörn
Please encrypt, key id 0xC8601622
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: memory leak huge number of digits mpz_mul,mpf_sqrt_ui

2021-02-26 Thread Paul Zimmermann
   Dear Susumu tsukamoto,

I tried valgrind with the following simplified program and it shows no memory
leak:

$ cat test_mul.c
#include "gmp.h"
int main()
{
long int num = 20; // 200,000,000 
long int ik;
mpz_t DC;
printf(" start:  num= %'ld \n", num);

mpz_init_set_str(DC, "1000",10); // DC=10^19
   
ik = 19;// DC=10^ik set   num/2 <= ik < num
while (ik * 2 < num) {
mpz_mul(DC, DC, DC);
ik = ik * 2;
}
mpz_clear(DC);
}

$ /usr/bin/g++ -g -Wall test_mul.c -o test_mul01 -lgmp
$ valgrind ./test_mul01
...
==23406== HEAP SUMMARY:
==23406== in use at exit: 0 bytes in 0 blocks
==23406==   total heap usage: 17 allocs, 17 frees, 231,296 bytes allocated
==23406== 
==23406== All heap blocks were freed -- no leaks are possible

Does valgrind report a memory leak with your original value num=2?

Best regards,
Paul Zimmermann
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs