C++ mpir : How to initialize mpz_t array?
<p><strong>Source:</strong></p>

<pre><code>//$ DO DECLARATION
#define VEC_MAX_SIZE 600000
mpz_t Vec[ VEC_MAX_SIZE ];

//$ DO INITIALIZATION
mpz_array_init( Vec[ 0 ], VEC_MAX_SIZE, 2000 ); // Stack overflow error - 3rd param
</code></pre>

<p><strong>Problem:</strong></p>

<p>The problem is that I don't know how to properly initialize an mpz_t array, which in this case is Vec. The error is stack overflow. I think it is caused by the 3rd parameter. Here is the protype/definition of mpz_array_init:</p>

<pre><code>#define mpz_array_init __gmpz_array_init
__GMP_DECLSPEC void mpz_array_init __GMP_PROTO ((mpz_ptr, mp_size_t, mp_size_t));
</code></pre>

<p><strong>Error:</strong></p>

<pre><code>Unhandled exception at 0x008e8377 in TestMPIR.exe: 0xC00000FD: Stack overflow.
</code></pre>

<p><strong>Note:</strong></p>

<p>I am using mpir 3.1.1 on Windows 7 64 Bit.</p>

<p>This one from mpir's example works fine:</p>

<pre><code>mpz_t Vec[ 20000 ];
mpz_array_init( Vec[ 0 ], 20000, 512 );
</code></pre>

<p><strong>ANSWER:</strong></p>

<p>Thanks to @Zeta for his/her awesome answer.
Correct me if I am wrong. I just want to post this here so other newbies can learn from it.</p>

<pre><code>#define MAX_VEC_SIZE 600000
</code></pre>

<p><strong>malloc method (should be for C style I guess):</strong></p>

<pre><code>mpz_t *Vec;

if( ( Vec = ( mpz_t *)::malloc( sizeof( mpz_t ) * MAX_VEC_SIZE ) ) == 0 ) {
    ::perror( "Out of memory" );
    return false;
}

//&gt; Initialize Vec loop ( ... )

::free( Vec );
</code></pre>

<p><strong>C++ style?</strong></p>

<pre><code>mpz_t *VecEx = new mpz_t[ MAX_VEC_SIZE ];

//&gt; Initialize VecEx loop ( ... )

delete [ ] VecEx;
</code></pre>

<p>This answer is based on @Zeta's answer (the accepted answer).</p>
