Search code examples
c++memorysizeofmultiprecisionzkcm

Multiprecision library zkcm and sizeof()


I am using the multiprecision complex number library (zkcm) and want to compare some results using complex<double>.

At one point I try to double check the memory of the variables using sizeof() but I get the same answer (32) no matter how big a memory I allocate the variables to; i.e. the following snippet prints 32 no matter what I use inside zkcm_set_default_prec():

zkcm_set_default_prec(128);
zkcm_class z;
cout << sizeof(z) << endl;

Is there another way than sizeof() to get the memory size of a variable?


Solution

  • I can't test it, and the documentation is a bit vague, but there's a method with this signature:

    int zkcm class::get_prec ( void ) const;
    

    Which is described like so:

    Get the internal precision of the object, namely, the precision used for each part of "this" complex number

    This might return the number of digits, which should be proportional to the amount of memory used. Of course the exact relationship is an implementation detail. The class itself probably just holds a pointer to a heap-allocated buffer where the digits live and some bookkeeping information. The sizeof operator (in C++) is fully static, i.e. evaluated at compile-time.