Summary

Although most compilers now use the same memory mapping of base types, this is not always the case, and not all programmers are fully aware of the implications of choosing a certain base type. That is why it is important for implementers to familiarize themselves with the sizes, ranges, and accessing speed of the standard C/C++ variables of their target environment. This chapter discussed ways to evaluate variable characteristics and gave practical examples of optimal use.

  • Speed of variables

    Not all base types are equally fast in access and arithmetic. It is possible for the integer to be much faster than the float and double in all arithmetic operations except division, depending on the characteristics of the target platform. Also bit fields can be quite fast until you try to do arithmetic with them. The scope and lifetime of a variable also has impact on the speed of use.

  • Design of structures and unions

    Because of alignment issues, the size of structures depends on the order in which their elements are declared. This alignment can be tweaked in several ways. Unions are always at least as large as their largest member; however, there are techniques for determining optimal use of unions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset