Lazy mpz allocation

Marco Bodrato bodrato at
Tue Sep 1 04:46:03 UTC 2015


Il Lun, 31 Agosto 2015 9:01 am, Niels Möller ha scritto:
> Me too! Actually, mpz_init could then be
>   static const mp_limb_t dummy_limb = 0;
>   #define INITIAL_MPZ {0, 0, &dummy_limb};
>   static const mpz_t initial_mpz = INITIAL_MPZ;
>   void
>   mpz_init (mpz_ptr x)
>   {
>      *x = initial_mpz; /* Inline or memcpy, depending on compiler */
>   }
> and later on we can consider some public interface for initializing an
> mpz without any library call.

I think that the condition to distinguish mpzs that where not allocated
yet should be ALLOC(x)==0. As a consequence, MPZ_ROINIT_N can be the
interface for initialising you ask for.
I'd like a sort of "copy-on-write" interface, that allocates the needed
limbs when we need to store a new value into a variable and possibly
(MPZ_REALLOC should, MPZ_NEWALLOC should not) copy the previous SIZE(x)
limbs to the new area...

Best regards,


More information about the gmp-devel mailing list