mpz_t caching

Vincent Lefevre vincent at
Mon Sep 7 09:20:26 UTC 2015

On 2015-09-04 12:28:21 +0200, Torbjörn Granlund wrote:
> I don't think libraries should hoard memory to compensate poor malloc
> implementations.  If that became common practice, applications would use
> more RAM without recourse.

OK, forget my mail. After looking at the MPFR source, I can't see
why mpz_t caching would be the solution and the only reason of the
improvement, because mpz_init and mpz_clear are used just at the
beginning and at the end of the function. I suspect that the cause
of the difference is that with mpz_t caching, the mpz_t's are
preallocated with a size that is large enough to avoid internal
reallocations in GMP (thus memory copies), but in such a case, the
right solution would be to use mpz_init2.

Vincent Lefèvre <vincent at> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the gmp-devel mailing list