integer size

David Gillies daggillies at
Thu Sep 30 23:41:38 CEST 2010

That's implementation dependent. The number base 256 is the effective
size in bytes, but you need to know a) the limb size b) the nail size
c) size of the sign flag and other top-level data in your
implementation to really ascertain how many bytes GMP wants for a
given number. mpz_t is basically a struct with a pointer to its limbs.
If your allocator is malloc- or new[] based then there's not a lot of
introspection allowed, and you shouldn't be poking around inside
deliberately opaque objects like mpz_t's anyway. Then there's whatever
overhead your particular system's memory allocator needs to manage
heap storage. It's not a well-posed problem. If you want rough and
ready, mpz_sizeinbase(n,16)/2 + 10% will do OK.

On Thu, Sep 30, 2010 at 1:13 AM, Ron Croonenberg
<ron.croonenberg at> wrote:
> sorry about the late reaction.
> I checked that section,  however it says "Return the size of 'op' measured
> in number of digits in the given base"
> However that is not what I want to know.  I want to know if I use an
> mpz_t integer what it's actual size (in bytes) in memory is, not the number
> of digits it has in a certain base.
> Ron
> On 9/17/2010 3:18 AM, Torbjorn Granlund wrote:
>> Ron Croonenberg<ron.croonenberg at>  writes:
>>   is there a way to find out how much space an integer uses?  of course
>>   in c one can do something like sizeof(int)  but when I use something
>>   like that with a gmp int I always end up getting 16. (even thought the
>>   integer is quite large.
>> Please see the fine manual, chapter Integer Functions, section
>> Miscellaneous Functions.
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at

David Gillies
San Jose
Costa Rica

More information about the gmp-discuss mailing list