Using allocation hooks to handle overflows?
Jan Wielemaker
wielemak at science.uva.nl
Fri Jul 27 16:44:57 CEST 2007
Hi,
I'm using GMP to provide bignum support for SWI-Prolog
(http://www.swi-prolog.org). This is all nice and operational for quite
a while, but some users start to complain on the unelegant exit that
results from GMP calls that make the system run out of memory. Ideally
these should produce a Prolog resource_error exception and not terminate
the program.
Now I've read the manual and it states quite clearly this cannot be done
:-( It suggests that might improve, but I don't see this mentioned in
the GMP-5 roadmap :-(
My situation is slightly special and possibly I can do something. Big
numbers normally live on the Prolog stacks, to which they are copied
after a bignum operation, represented such that they can act as
read-only bignums in other operations. This requires some non-portable
hacking in the bignum structures. As long as this doesn't change too
often that is acceptable to me.
This means bignums as allocated by the library are only used temporary,
which assumes one should be able to redefine the allocation handlers,
keeping track of what is allocated and using a longjmp on overflow. In
the setjmp recovery we can deallocate all memory allocated since we
entered setjmp.
Would this work?
Thanks --- Jan
More information about the gmp-discuss
mailing list