struct structure can strengthen the management of variables, increase the readability of the program, but on the other hand, the structure will increase the cost of the program.
Look at the following section of 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 = 30 0.f;return 0;}
using the Disassembly tool,
<strong><span style= "FONT-SIZE:18PX;" ></span></strong><pre name= "code" class= "cpp" >TS.A = 100;ts.b = 200;TS.C = 300.F;
Assigning 3 variables to a struct, in fact the assembly code under 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
As you can see from the assembly code, in addition to the first variable in the struct, the next variable needs to be offset on the basis of the struct's header address, rather than the struct:
A = 100;b = 200;c = 300.F;
The assembly code is as follows:
mov dword ptr [a],64h mov dword ptr [b],0c8h mov
significantly less one-step address subtraction.
However, in the case of release, the compiler optimizes the program by default, because the assembly code under optimization cannot be viewed, so the actual overhead is not ascertained.
struct structure increases program overhead