Question about mpz_set_str

Minh Nguyen md6nguyen@yahoo.com
Fri, 3 Jan 2003 13:25:23 -0800 (PST)


--0-33791928-1041629123=:60730
Content-Type: text/plain; charset=us-ascii


Hi, I want to build a GMP integer from a decimal string so I use 

mpz_set_str(rop, str, 10);

Now, the thing is that I want to have total control over memory management so I pre-allocate a buffer for rop and initialize all the header instead of calling mpz_init (I know this is bad but I have to do that for efficiency).

My question is: Given that the decimal string has N digits, how many limbs should be allocated to rop so that it is guaranteed that GMP won't re-allocate the buffer for rop? 

Mathematically, N decimal digits should fit in ceil( N * ln(10)/ln(B) ) limbs where B is either 2^32 or 2^64. However, even when I allocate these many limbs to rop GMP still re-allocate the buffer of rop. Why does GMP have to reallocate memory when it is not necessary? 

Thanks,

Minh

 

 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-33791928-1041629123=:60730
Content-Type: text/html; charset=us-ascii

<P>Hi, I want to build a GMP integer from a decimal string so I use </P>
<P>mpz_set_str(rop, str, 10);</P>
<P>Now, the thing is that I want to have total control over memory management so I pre-allocate a buffer for rop and initialize all the header instead of calling mpz_init (I know this is bad but I have to do that for efficiency).</P>
<P>My question is: Given that the decimal string has N digits, how many limbs should be allocated to rop so that it is guaranteed that GMP won't re-allocate the buffer for rop? </P>
<P>Mathematically, N decimal digits should fit in ceil( N * ln(10)/ln(B) ) limbs where B is either 2^32 or 2^64. However, even when I allocate these many limbs to rop GMP still re-allocate the buffer of rop. Why does GMP have to reallocate memory when it is not necessary? </P>
<P>Thanks,</P>
<P>Minh</P>
<P>&nbsp;</P>
<P>&nbsp;</P><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-33791928-1041629123=:60730--