Question

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?

Was it helpful?

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.

OTHER TIPS

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

sizeof() is evaluated at compile time and there is no way in C++ language to change that value at runtime, period. There could be some interface that provides information you need (either directly or indirectly), could be not. But sizeof() definitely is not the way to achieve what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top