A different way is to stop using the mpz_* functions, and use only the lower level mpn_* functions instead. But then you lose functionality, complex algorithms, e.g. powm, isn't available in the mpn interface.
What does mpn_pow do if it runs out of memory, and why doesn't mpz_pow do the same?
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2002-11-20 15:40: Subject: Gmp
As you say, the out-of-memory problem is a little hard to fix without changing GMP. One "solution" that has been proposed on the gmp list:
- Register your own memory allocation functions with gmp. Put a
jmp-buffer somewhere that the memory allocation function will longjmp to on failure.
- Around each call to a gmp function, first put some mark into the
memory allocation structure.
Then call setjmp.
If the memory allocation function longjmps out, you know that
you're out of memory. In this case, check for the mark you installed in step 2, so that you can free any temporary storage that was allocated before the failure.
- For a threaded program, both the marking and the jmp buffer has to
be in thread-local storage.
Not particularly pretty...
A different way is to stop using the mpz_* functions, and use only the lower level mpn_* functions instead. But then you lose functionality, complex algorithms, e.g. powm, isn't available in the mpn interface.
/ Niels Möller ()