Use Appropriate Data Types to Manage 64-bit Data Size

Submit New Article

March 10, 2009 9:00 PM PDT



Challenge

Ensure that you are using 32-bit or 64-bit data types as appropriate for your variables. Caution in this area conserves resources and avoids data bloat.


Solution

If a variable will not need to count past 232, (4,294,967,296), for the forseeable future, code it as a 32-bit type, rather than a 64-bit data type. If you know that a variable does not need to be pointer polymorphic (scale with the architecture), use the following guideline to decide whether to type it as 32-bit instead of 64-bit. (This guideline is based on a data-expansion model of 1.5 bits per year over 10 years.)

  • Consider your largest data range, for example 0 ...1,000,000.
  • Multiply the range by 1.510 (approximately 58).
  • If the result is still less than 232, code the variable as a 32-bit variable, such as int.
  • If the result is larger than 232, or you know of an impending need for capacity increases, code the variable as a 64-bit variable, such as long (for UNIX/64* only) or __int64 (for Windows* 2000, 64-bit only).

Additional issues related to managing data size and avoiding data bloat during migration to 64-bit Intel architecture are addressed in separate items:

 


Source

Preparing Code for the IA-64 Architecture (Code Clean)