Best way to know how much memory is used by an mpz_class object

Roberto Bagnara bagnara at
Mon Dec 6 16:31:25 CET 2004

In my application I need a way to compute the amount of memory
that is used by an object of type `mpz_class'.
What I do now is something like

   sizeof(x) + x.get_mpz_t()[0]._mp_alloc*SIZEOF_MP_LIMB_T

which, however, relies on the low-level implementation of
Is there a more portable or better way to achieve the same effect?
All the best,


Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
mailto:bagnara at

More information about the gmp-discuss mailing list