GMP Native Interface for .NET
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)

public static void mpz_realloc2( mpz_t x, mp_bitcnt_t n )
Public Shared Sub mpz_realloc2 ( x As mpz_t, n As mp_bitcnt_t )
public: static void mpz_realloc2( mpz_t^ x, mp_bitcnt_t n )
static member mpz_realloc2 : x : mpz_t * n : mp_bitcnt_t -> unit
Parameters
- x
- Type: Math.Gmp.Nativempz_t
The integer. - n
- Type: Math.Gmp.Nativemp_bitcnt_t
The number of bits.

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.

// 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);
' Create and initialize new integer x. Dim x As New mpz_t() gmp_lib.mpz_init(x) ' Set the value of x to a 77-bit integer. Dim value As 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, 512UI) Dim s As char_ptr = 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, 2UI) 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)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
