mpz_export to file?

paul zimmermann Paul.Zimmermann at inria.fr
Wed Dec 9 09:10:20 UTC 2015


       Hi,

mpz_export() exports an integer to some allocated array. For saving huge
integers to a file, this is not optimal since one has first to allocate a
huge array in memory, "export" the mpz_t to that array, and then copy that
array to memory.

Would it be possible to have a function that exports directly to a file
(and of course the corresponding import function)?

void mpz_export_file (FILE *f, mpz_t op);
void mpz_import_file (mpz_t op, FILE *f);

One could imagine a format where several numbers can be exported in the same
file:

   f = fopen ("toto", "w");
   mpz_export_file (f, a);
   mpz_export_file (f, b);
   mpz_export_file (f, c);
   fclose (f);
   ...
   f = fopen ("toto", "r");
   mpz_import_file (a, f);
   mpz_import_file (b, f);
   mpz_import_file (c, f);
   fclose (f);

Paul


More information about the gmp-devel mailing list