I’m relatively new to using C/C++. I’m currently using Visual Studio 2010 and am analyzing some code written by someone else. I was notified of an issue where I have a function using too much memory. Virtually all of the pointers in it are Float_64 and I was wondering what kind of repercussions there were if I were to change them to Float_32. How much memory is used by Float_64 and Float_32 and is there any data loss by switching? I apologize if this has already been asked however I couldn’t seem to find it.
Thank you!
Float_64andFloat_32are not C++ types defined in the C++ Standard, so they must be something specific to your application or the libraries you are using.However, if the names are remotely sane, the size of a
Float_64will be 64 bits (8 Bytes on modern architectures), and aFloat_32will be 32 bits. Therefore, if you switch to usingFloat_32instead ofFloat_64, you will reduce the memory pressure of the floats themselves by half. Now, that’s to say nothing of the pointers to the values, which will still be the same size as they were. So, consider:In the above code,
my64is half thesizeof()asmy32— 64 and 32 bits (8 and 4 bytes) respectively. However,my64_ptrandmy32_ptrare pointers, and pointers are the same size, regardless of what they point to.The reprecussions are another consideration. A
Float_32has, presumably, less precision than aFloat_64— perhaps half as much, or even less. If you need floats with a very high degree of signifigance, you may loose precision when converting to the smaller type. The only way to know for sure is to examine the specifications for both types w.r.t. precesion, and analyze the data you need to manipulate. However, as a general rule of thumb, the lower precision is very possibly sufficient for most uses.