
Matt Carter wrote:
nisse@lysator.liu.se (Niels Möller) writes:
There should be a list somewhere of "these are the things we want to change next time we make a new version that isn't 100% compatible", and deleting gmp_errno should be on that list. IMHO.
Add to that list, the ability to recover from memory allocation failures.
Currently, the GMP functions that call __gmp_allocate_func() generally do not check the return value for NULL. Further, many of them return void, so changing them to return an out-of-memory error code would change the GMP API.
We use GMP in a mission critical system which regularly hits the limits of available memory, so GMP's behavior of requiring the application to terminate when out of memory was unacceptable.
This is indeed unacceptable in many situations. And now that GMP provides a C++ interface, it is really desirable that a bad_alloc exception is thrown on memory allocation failure. I would say that it is desirable _independently_ from the application (in our specific application we cannot simply afford not to have it). What we do now is to provide our own exception-throwing, C++ allocation functions, installing them with
mp_set_memory_functions(cxx_malloc, cxx_realloc, cxx_free);
and making sure GMP has been compiled with the "-fexceptions" flag of GCC, something that can be done by configuring GMP with a command like
CPPFLAGS=-fexceptions my/path/to/gmp-4.0.1/configure ...
This seems to work quite well for us. I know this solution is not blessed by the GMP maintainers but, as far as I can tell, there is no other option at the moment. All the best
Roberto
participants (1)
-
Roberto Bagnara