Additional memory handler features.

Niels Möller nisse at lysator.liu.se
Sun Jan 4 15:50:27 UTC 2015


Marc Glisse <marc.glisse at inria.fr> writes:

> Er, people have been using the custom allocators for (possibly
> imperfect) recovery on allocation failure for years. PPL's configure
> script complains if gmp was compiled without -fexceptions for that
> reason. Apparently SWI-Prolog uses longjmp
> (http://stackoverflow.com/a/14245611/1918193).

Ok, good to hear about some examples. We ought to investigate these
before deciding what to do to improve error recovery hooks.

> Although itch/scratch may force a compromise between overestimating
> the space required or spending too long estimating it, which I hope
> won't penalize small numbers too much.

I think a typical itch function will look like

  mp_size_t
  foo_itch (mp_size_t n)
  {
    if (LIKELY (BELOW_THRESHOLD (n, FOO_THRESHOLD)))
      return n; /* Or possibly zero or some other constant */
    else
      ... something possibly more complicated, perhaps
          a full "synthetic computation" ...
  }

So it's a function call (I think we usually want to avoid macros here),
but for small operands it's just the function call overhead and a
well-predicted branch.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list