In C ++, define the communication protocol. h header file. Sometimes # pragma pack (push, 1) is used to modify the memory alignment of Data Structure members (1 byte alignment)
Assume that there is package. h
// Filename: package. h
# Pragma pack (push, 1)
Struct performance_test
{
Int iflag1;
Char szname [32];
}
//...
# Pragma pack (POP, 1)
If you reference package. h In other C ++ header files, note that the order of package. h affects other referenced header files (actual results under vs2010)
According to the actual measurement, we can conclude that include "package. H" is best placed in the first line of include,
Otherwise, it may affect the heap or stack memory layout of objects defined by other header files, or even cause heap crash or stack upt.
For example:
// Filename: transmit. h
# Pragma once
# Include "otherhead1.h"
# Include "package. H"
# Include "otherhead2.h"
//......
The above sequence may result in an exception in the data member data of the object defined in otherhead2.h or the function stack is damaged.
The insurance method is to put package. h In the first line of include.
======================================
Supplement the truth of the problem. # The Pragma pack (POP, 1) is incorrect,
# Pragma pack (POP) to restore the default memory alignment