Since there is an MPIR tag, this is probably about MPIR, a fork of GMP. And in the current documentation (PDF only — no online HTML), under the heading 'Initializing integers', you can find:
void mpz_init2(mpz_t integer, mp_bitcnt_t n)
Initialize
integer
, with space for
n
bits, and set its value to 0.
n
is only the initial space,
integer
will grow automatically in the normal way, if necessary,
for subsequent values stored.
mpz_init2
makes it possible to avoid such reallocations if a
maximum size is known in advance.
If this was for GMP, you can read the online manual on Initializing integers to find:
— Function: void mpz_init2(mpz_t x, mp_bitcnt_t n)
Initialize x
, with space for n
-bit numbers, and set its value to 0. Calling this function instead of mpz_init
or mpz_inits
is never necessary; reallocation is handled automatically by GMP when needed.
While n
defines the initial space, x
will grow automatically in the normal way, if necessary, for subsequent values stored. mpz_init2
makes it possible to avoid such reallocations if a maximum size is known in advance.
In preparation for an operation, GMP often allocates one limb more than ultimately needed. To make sure GMP will not perform reallocation for x
, you need to add the number of bits in mp_limb_t to n
.
The two are essentially the same.