This article has participated in the call for good writing activities, click to view: back end, big front end double track submission, 20,000 yuan prize pool waiting for you to challenge!

CPP: Defines the entry point for the console application
//

#include "stdafx.h"
#include <windows.h>

//////////////////////////////////////////////////////////////////////////
// 1. Verify the efficiency of data member access at different locations
/* Code to access data members is more compact if the member's offset relative to the beginning of the structure or class is less than 128, because the offset can be represented as an 8-bit signed number. If the offset relative to the beginning of a structure or class is 128 bytes or greater, then the offset must be represented as a 32-bit number (the instruction set has no offset between 8 and 32 bits). The offset of b is 400. Any code that accesses B through Pointers or member functions such as ReadB needs to encode the offset as a 32-bit number. If A and B are swapped, both can be accessed by offsets encoded as 8-bit signed numbers, or no offsets at all. This makes the code more compact for more efficient use of the Cache. Therefore, it is recommended that large arrays and other large objects come last in a structure or class declaration and that the most commonly used data members come first. If you cannot contain all the data members in the first 128 bytes, put the most frequently used members in the first 128 bytes. memset(obj.a, 0, 2*1000); 005C3C9C push 7D0h 005C3CA1 push 0 005C3CA3 lea eax,[obj] 005C3CA9 push eax 005C3CAA call _memset (05C1078h) 005C3CAF Add esp,0Ch obj. B = 1.0; 005C3CB2 movsd xmm0,mmword ptr ds:[5C5860h] 005C3CBA movsd mmword ptr [ebp-18h],xmm0 obj.c = 1; 005C3CBF mov dword ptr [ebp-10h],1 MyStruct2 obj2; memset(obj2.a, 0, 2 * 1000); 005C3CC6 push 7D0h 005C3CCB push 0 005C3CCD lea eax,[ebp-0FC4h] 005C3CD3 push eax 005C3CD4 call _memset (05C1078h) 005C3CD9 add esp,0Ch obj2.b = 2.0; 005C3CDC movsd xmm0,mmword ptr ds:[5C5868h] 005C3CE4 movsd mmword ptr [obj2],xmm0 obj2.c = 2; 005C3CEC mov dword ptr [ebp-0FC8h],2 */

// Structure 1
struct MyStruct     
{
    short a[1000];
    double b;
    int c;
};

// Struct 2
struct MyStruct2
{
    double b;
    int c;
    short a[1000];
};

//////////////////////////////////////////////////////////////////////////
//
int _tmain(int argc, _TCHAR* argv[])
{
    MyStruct obj;
    memset(obj.a, 0.2*1000);
    obj.b = 1.0;
    obj.c = 1;

    MyStruct2 obj2;
    memset(obj2.a, 0.2 * 1000);
    obj2.b = 2.0;
    obj2.c = 2;

    system("pause");
	return 0;
}
`
Copy the code