Struct structure will increase program overhead
On the one hand, the struct structure can enhance the management of variables and increase the readability of the program, but on the other hand, the structure will also increase the overhead of the program.
See the following code:
struct TEST_S{int a;int b;float c;};int _tmain(int argc, _TCHAR* argv[]){TEST_S ts;int a;int b;int c;ts.a = 100;ts.b = 200;ts.c = 300.f;a = 100;b = 200;c = 300.f;return 0;}
Use disassembly tools,
ts.a = 100;ts.b = 200;ts.c = 300.f;
Assign values to the three variables of the struct. In fact, the assembly code in Debug is:
mov dword ptr [ts],64h mov dword ptr [ebp-0Ch],0C8h movss xmm0,dword ptr ds:[0BA5858h] movss dword ptr [ebp-8],xmm0
From the assembly code, we can see that in addition to the first variable of the struct, the next variable needs to add an offset based on the header address of the struct, rather than the struct, as shown below:a = 100;b = 200;c = 300.f;
The Assembly Code is as follows:mov dword ptr [a],64h mov dword ptr [b],0C8h mov dword ptr [c],12Ch
Obviously, one step of address Subtraction is missing.
However, in the case of Release, the compiler optimizes the program by default. The compiled code Under optimization cannot be viewed, so it cannot identify the actual overhead.