Converting array to mpz_t

Michel Bardiaux mbardiaux at peaktime.be
Fri Jan 30 10:46:34 CET 2004


XiChimos wrote:

> I am doing a network program that reads data off of a socket and puts it 
> into an array.  How would I read in this data that is in the raw format, 
> as spit out by mpz_out_raw(), into an mpz_t?  It is probably trivial, 
> but it needs to be an efficient method.  I am not using mpz_inp_str() 
> because it has a maximum base of 36, and I assume raw is base 2^8.  
> Thanks for the help.
> 
> Chris

The lack of memory-resident files in C is indeed very annoying. This 
could work:

Open a pipe(2)
write(2) the mpz_out_raw data on pipe[1]
fdopen a stream on pipe[0]
call mpz_inp_raw

Alternative solution: socket and dup instead of pipe.

Of course this will fail if the raw data is too large. I dont know if 
setsockopt would work on a pipe. But it should work on a socket.

HTH,
-- 
Michel Bardiaux
Peaktime Belgium S.A.  Bd. du Souverain, 191  B-1160 Bruxelles
Tel : +32 2 790.29.41



More information about the gmp-discuss mailing list