gmp_lib_mpz_realloc Method |
Namespace: Math.Gmp.Native
The value in integer is preserved if it fits, or is set to 0 if not.
mpz_realloc2 is the preferred way to accomplish allocation changes like this. mpz_realloc2 and _mpz_realloc are the same except that _mpz_realloc takes its size in limbs.
// 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 50 limbs, and assert that its value has not changed. gmp_lib._mpz_realloc(x, 50); 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 1 limb, and assert that its value has changed to 0. gmp_lib._mpz_realloc(x, 1); 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);