How to manage mpz_t array

I use GMP and I need an array mpz_t. sizeof(mpz_t)gives 16, but the numbers that I keep are significantly larger. Does mpz_t"in place" increase , i.e. e. I need to allocate more memory and allow growth in place, or GMP allocates space for them elsewhere and just keeps the links (in this case, I suppose, I don’t have to take any special precautions).

+4
source share
4 answers

In the GNU MP 3.11 manual, the corresponding lines correspond.

GMP variables are small, contain only a couple of sizes and pointers to the highlighted data. After initializing the GMP variable, you don’t need to worry about space allocation. All functions in GMP automatically allocate additional space when the variable is not enough. However, they do not reduce space while maintaining a lower value.

So, I think this answers your question.

+3
source

It is safe to declare an array to hold multiple values mpz_t. According to the GNU MP manual :

mpz_t . GMP, . , mpz_t , , , GMP.

+5

, mpz_t. GMP:

mpz_t vec[20];

, mpz_t (_mp_d) "", .

, :

typedef __mpz_struct mpz_t[1];

GMP 5.1.3, mpz_t __mpz_struct, . . , .

+4
source

Think of it this way: if you declare one variable mtz_t, the space for this variable is statically allocated by the compiler at compile time. How can I resize a variable at runtime? It cannot, that means using it in an array is excellent.

+3
source

Source: https://habr.com/ru/post/1616324/


All Articles