Click or drag to resize
gmp_libmpz_realloc2 Method
Change the space allocated for x to n bits.

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_realloc2(
	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

The value in x is preserved if it fits, or is set to 0 if not.

Calling this function is never necessary; reallocation is handled automatically by GMP when needed. But this function can be used to increase the space for a variable in order to avoid repeated automatic reallocations, or to decrease it to give memory back to the heap.

Examples
// Create and initialize new integer x.
mpz_t x = new mpz_t();
gmp_lib.mpz_init(x);

// Set the value of x to a 77-bit integer.
char_ptr value = new char_ptr("1000 0000 0000 0000 0000");
gmp_lib.mpz_set_str(x, value, 16);

// Resize x to 512 bits, and assert that its value has not changed.
gmp_lib.mpz_realloc2(x, 512U);
char_ptr s = gmp_lib.mpz_get_str(char_ptr.Zero, 16, x);
Assert.IsTrue(s.ToString() == "1000 0000 0000 0000 0000".Replace(" ", ""));

// Resize x to 2 bits, and assert that its value has changed to 0.
gmp_lib.mpz_realloc2(x, 2U);
Assert.IsTrue(gmp_lib.mpz_get_si(x) == 0);

// Release unmanaged memory allocated for x and string values.
gmp_lib.mpz_clear(x);
gmp_lib.free(value);
gmp_lib.free(s);
See Also