gmp's c++ interface / mpz_class

Florian Weimer
Wed Oct 19 10:28:53 GMT 2022

* Pedro Alves:

> Hmm.  Since we don't need infinite precision, it will end up a lot
> more efficient to roll our own type, with fixed (or templated) storage
> size.  Like a simplified version of GCC's wide_int.  Not sure yet
> whether efficiency really matters in practice, but I suspect it does.
> I'd still be curious about GMP's native C++ interface.

I tried to use it recently in a hobby project, but it turned out to be a
poor fit because it's not integrated well with C++11 and later features
(no move constructors, no rvalue references).  The unconditional use of
malloc is rather off-putting, too.

I'm contemplating to use tagged integers/pointers as the main
representation, with heap allocation only on demand, maybe using the the
mpn* functions directly, or perhaps copy things out of a long-lasting
mpz_t object that's used as a temporary for arithmetic.

For 72-bit integers, that seems a bit over the top, though.


More information about the Gdb mailing list