Paul.Zimmermann at loria.fr
Thu Jun 3 22:34:09 CEST 2010
> > Why does GMP allocate 3 limbs for z (which fits into 2 limbs), and allocate
> > 3 limbs for r (which fits into 1 limb)?
> does it cause trouble somehow? It is only a constant number (1 for the
> string, 2 for the division, in the worst case) of extra limbs, the
> documentation mentions this can happen and many gmp functions do it (the
> worst being maybe z-z which allocates size(z)+1).
yes it causes trouble in MPFR, where we use mpz functions with our own
allocation function instead of mpz_init, to replace calls to malloc() by
calls to alloca(). However this approch works only if we are able to bound
the maximal allocated size, since if mpz_ functions call realloc() we are dead.
The problem is that the maximal allocated size (wrt actual size) in mpz is
not documented, and we can only guess it.
More information about the gmp-devel