How do I get the memory size of a BigInt?

I think you can get the allocated memory via the .alloc field, e.g.

julia> b = big(2)^512; (b.size, b.alloc)
(9, 13)

julia> 13 * Base.GMP.BITS_PER_LIMB / 8 # total number of allocated bytes
104.0
3 Likes