Can 1 byte align the cause of memory corruption?

Suppose you have a C ++ structure (using MFC, a compiled 32-bit version), which is defined as follows:

#pragma pack (push, 1)
struct foo
{
   float f;
   int z;
   DWORD k;
   BYTE b;
   int i;
}; 
#pragma pack (pop,1)

Now you create a file with memory mapping using CreateFileMappingin Windows, and then write this contents of the structure to this memory area. This is a globally accessible memory card.

Now you have a C # application (32 bits compiled) and you create a structure similar to this:

[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct foo
{
   double f;
   int z;
   int k;
   byte b;
   int i; 
}

, # , . f double, , , . float, .

, , 1 ?

, , / , , .

, ? , .

+4
2

, , float, double. , , . 4 , 4 .

, , , . , , , 4 , , .

. 4 , , .

:

  • , .
  • , .
+4

, . # promises 4 32- , 32- . , , .

+1

All Articles