Click or drag to resize
gmp_libmpz_init2 Method
Initialize x, with space for n-bit numbers, and set its value to 0.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void mpz_init2(
	mpz_t x,
	mp_bitcnt_t n
)

Parameters

x
Type: Math.Gmp.Nativempz_t
The integer.
n
Type: Math.Gmp.Nativemp_bitcnt_t
The number of bits.
Remarks

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.

Examples
// Create a new integer x, and initialize its size to 300 bits.
mpz_t x = new mpz_t();
gmp_lib.mpz_init2(x, 300);

// Assert that the value of x is 0.
Assert.IsTrue(gmp_lib.mpz_get_si(x) == 0);

// Release unmanaged memory allocated for x.
gmp_lib.mpz_clear(x);
See Also