I think that
cout << sizeof(as_array) << endl;
always returns the required storage for two pointers to double on a given machine, possibly with breaks, to comply with packing rules. Optimization has helped reduce the size of the data structure data warehouse. Instead, the compiler can fully optimize your code in the real world. Therefore, if you have code:
double a=100; double b=200; as_array arr(&a, &b); std::cout << arr[0] << std::endl;
can lead to full storage optimization for the structure, since the compiler knows how these values ββare processed through your code. But listing sizeof (arr) still gives you the theoretical size of the structure.
In any case: if you want to improve optimization results, you should write better code! Create const methods if they are const ! If you are using C ++ 11, use constexpr if possible.
source share