Http://blog.csdn.net/yysdsyl/article/details/1885795
People who read "C ++ Object Model" often mistakenly think that the compiler is filled with the length of the computer, as shown below:
Class
{
Double;
Char B;
};
Sizeof (A) =?
People who do not know how to fill in will think it is 9, and those who read the C ++ Object Model (like me) will often think it is 12. Last night, I saw a similar question in the programmer interview guide, at first, I thought the answer was wrong .. I did not know after a try today. I was wrong .. The answer to the above question (by default in the compiler) is 16, which is true for vc6.0, mingw, and vs.net ..
In the programmer interview book, the principle of CPU optimization is roughly like this: for n-byte elements (n = 2, 4, 8 ......) The first address can be divisible by N to obtain the best performance. This principle can be followed when designing the compiler. That is to say,By default, the compiler usually takes the maximum variable length as the fill length, instead of the byte length.. Of course, you can also use # pragma pack (n) to specify the padding length of the compiler. This should not be the case with the highest CPU efficiency.
Another netizen discussed whether a class contains another class object and whether it is filled with the length of the containing class? This is not the case,Fill in according to the maximum length of the basic type in the language
Misunderstanding of the compiler on memory fill Length