mpz_limbs interface
Marc Glisse
marc.glisse at inria.fr
Tue Jan 21 15:30:38 UTC 2014
On Tue, 21 Jan 2014, Niels Möller wrote:
>> MPFR_ASSERTN (nbits >= 1);
>> /* To be sure to avoid the potential allocation of mpz_urandomb */
>> ALLOC(z) = SIZ(z) = MPFR_PREC2LIMBS (nbits);
>> PTR(z) = mp;
> [...]
>> mpz_urandomb (z, rstate, nbits);
>
> I think this is brittle, and I don't think this style should be
> officially supported in the public gmp interface. mpz_urandomb is not
> included in mini-gmp, but if you, e.g., try the same with other
> functions, it will most likely break with mini-gmp which assigns many of
> the output parameters using mpz_swap.
We already have function mpz_array_init which encourages thinking of the
buffer as belonging to a variable, with all other functions keeping this
association as long as the buffer is large enough. Gratuitous extra
alloc+dealloc pairs can have a horrible performance effect. That's not an
issue for mini-gmp because performance is not a concern, but it is for
mpfr and many users, and even if they rewrite the code to accomodate
mini-gmp, they will probably want to keep the current one for regular gmp
(with suitable #if).
--
Marc Glisse
More information about the gmp-devel
mailing list