Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I manage an array of mpz_t

Tags:

c

gmp

I'm using GMP and I need an array of mpz_t. sizeof(mpz_t) gives 16, but the numbers I'm storing are considerably larger than that. Does mpz_t grow "in place", i. e. do I need to allocate more memory and allow for growth in-place, or does GMP allocate the space for them elsewhere and just keep references (in which case, I'm assuming, I won't have to take any special precautions.)

like image 678
Janis F Avatar asked Dec 05 '22 01:12

Janis F


1 Answers

It is safe to declare an array to store a number of mpz_t values. According to the GNU MP manual:

mpz_t is actually implemented as a one-element array of a certain structure type. This is why using it to declare a variable gives an object with the fields GMP needs, but then using it as a parameter passes a pointer to the object. Note that the actual contents of an mpz_t are for internal use only and you should not access them directly if you want your code to be compatible with future GMP releases.

like image 90
autistic Avatar answered Dec 29 '22 11:12

autistic