Zero This
Posted: Thu Mar 17, 2016 2:41 am
Hello.
In some of my classes I use the following code to zero the entire class.
This generates this code, which is not what I am after. I clears from 0 to sizeof(T)
Is there a way to do this?
Regards, Ali
In some of my classes I use the following code to zero the entire class.
Code: Select all
FIL void tSystem::tOS_GenericOS::tCPU::Init()
{
ZeroThis();
Code: Select all
Util.Zero(this);
Code: Select all
TCF void Zero(T& Me)
{
::memset(&Me, 0, sizeof(T));
}
Code: Select all
0000000000306cd0 <_ZN6Kernel7tSystem13tOS_GenericOS4tCPU4InitEv.constprop.113>:
306cd0: 31 c0 xor eax,eax
306cd2: 66 0f 1f 44 00 00 nop WORD PTR [rax+rax*1+0x0]
306cd8: c6 00 00 mov BYTE PTR [rax],0x0
306cdb: c6 40 01 00 mov BYTE PTR [rax+0x1],0x0
306cdf: 48 83 c0 08 add rax,0x8
306ce3: c6 40 fa 00 mov BYTE PTR [rax-0x6],0x0
306ce7: c6 40 fb 00 mov BYTE PTR [rax-0x5],0x0
306ceb: c6 40 fc 00 mov BYTE PTR [rax-0x4],0x0
306cef: c6 40 fd 00 mov BYTE PTR [rax-0x3],0x0
306cf3: c6 40 fe 00 mov BYTE PTR [rax-0x2],0x0
306cf7: c6 40 ff 00 mov BYTE PTR [rax-0x1],0x0
306cfb: 48 3d 18 02 36 00 cmp rax,0x360218
306d01: 75 d5 jne 306cd8 <_ZN6Kernel7tSystem13tOS_GenericOS4tCPU4InitEv.constprop.113+0x8>
Regards, Ali