Go to the first, previous, next, last section, table of contents.
The functions for integer arithmetic assume that all integer objects are
initialized. You do that by calling the function mpz_init
.
- Function: void mpz_init (mpz_t integer)
-
Initialize integer with limb space and set the initial numeric value to
0. Each variable should normally only be initialized once, or at least cleared
out (using
mpz_clear
) between each initialization.
Here is an example of using mpz_init
:
{
mpz_t integ;
mpz_init (integ);
...
mpz_add (integ, ...);
...
mpz_sub (integ, ...);
/* Unless the program is about to exit, do ... */
mpz_clear (integ);
}
As you can see, you can store new values any number of times, once an
object is initialized.
- Function: void mpz_clear (mpz_t integer)
-
Free the limb space occupied by integer. Make sure to call this
function for all
mpz_t
variables when you are done with them.
- Function: void * _mpz_realloc (mpz_t integer, mp_size_t new_alloc)
-
Change the limb space allocation to new_alloc limbs. This function is
not normally called from user code, but it can be used to give memory back to
the heap, or to increase the space of a variable to avoid repeated automatic
re-allocation.
- Function: void mpz_array_init (mpz_t integer_array[], size_t array_size, mp_size_t fixed_num_bits)
-
Allocate fixed limb space for all array_size integers in
integer_array. The fixed allocation for each integer in the array is
enough to store fixed_num_bits. If the fixed space will be insufficient
for storing the result of a subsequent calculation, the result is
unpredictable.
This function is useful for decreasing the working set for some algorithms
that use large integer arrays.
There is no way to de-allocate the storage allocated by this function.
Don't call mpz_clear
!
Go to the first, previous, next, last section, table of contents.