Default Memory Allocation for MSVC 8

According to MSDN , the command /Zpdefaults to 8, which means using 64-bit alignment boundaries. I have always assumed that for 32-bit applications, the MSVC compiler will use 32-bit boundaries. For instance:

struct Test
{
   char foo;
   int bar;
};

The compiler will execute it as follows:

struct Test
{
   char foo;
   char padding[3];
   int bar;
};

So, since it is /Zp8used by default, does this mean that my pad is 7 + 4 bytes using the same example above:

struct Test
{
   char foo;
   char padding1[7];
   int bar;
   char padding2[4];
}; // Structure has 16 bytes, ending on an 8-byte boundary

It's a little funny, isn't it? I do not understand? Why such a great addition is used, it seems like a waste of space. Most types on a 32-bit system do not even use 64-bit systems, so most variables will be indented (possibly more than 80%).

+5
3

, . . Char 1 , 2, int 4, 8. , , , .

8 , , 8. , , , 8. , . , SIMD, 16 .

+9

, 8 . :

the smaller member type or n-byte boundaries

- - " ". , .

struct x {
    char c;
    int y;
};
std::cout << sizeof(x);
std::cout << "offsetof(x, c) = " << offsetof(x, c) << '\n';
std::cout << "offsetof(x, c) = " << offsetof(x, y) << '\n';

8, 0, 4, , int 4 .

+3

See this answer from Eric Wang for detailed rules. This answer very clearly and unequivocally explains how filling is done. This is a link to Eric Wang's answer:

0
source

All Articles