From: Ben Voigt [C++ MVP] on


"Vincent Fatica" <vince(a)blackholespam.net> wrote in message
news:4aa3de92$1(a)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

From: Vincent Fatica on
On Tue, 8 Sep 2009 15:01:40 -0500, "Ben Voigt [C++ MVP]"
<bvoigt(a)newsgroup.nospam> wrote:

|
|
|"Vincent Fatica" <vince(a)blackholespam.net> wrote in message
|news:4aa3de92$1(a)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.

Tried that ... results in a call to _memset.
--
- Vince
From: Giovanni Dicanio on
Vincent Fatica ha scritto:

> |You can use the ZeroMemory macro, which results in a call to ntdll.dll's
> |RtlZeroMemory routine instead of pulling in the CRT.
>
> Tried that ... results in a call to _memset.

In WinNT.h I read:

#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))


Giovanni


From: Ben Voigt [C++ MVP] on


"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote in message
news:erxaMWNMKHA.4124(a)TK2MSFTNGP04.phx.gbl...
> Vincent Fatica ha scritto:
>
>> |You can use the ZeroMemory macro, which results in a call to ntdll.dll's
>> |RtlZeroMemory routine instead of pulling in the CRT.
>>
>> Tried that ... results in a call to _memset.
>
> In WinNT.h I read:
>
> #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))

Yes, but I think there is a real exported function in ntdll.dll

So maybe RtlZeroMemory needs to be #undef-d

>
>
> Giovanni
>
>
From: Vincent Fatica on
On Tue, 8 Sep 2009 13:32:29 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:

|in ntdll.dll.
|
| 1180 49B 0000E5C6 _CIcos = __CIcos
| 1181 49C 0000E682 _CIlog = __CIlog

I tried linking an old, big project with ntdll.dll. That project also uses
libcmt.dll (/MT) and it uses many functions which are available in both places.
Even so, I get only one error:

>LIBCMT.lib(_wctype.obj) : error LNK2005: _iswdigit already defined in ntdll.lib(ntdll.dll)

Is there a way to fix that? In general, is there a way to take what's available
in ntdll.dll from ntdll.dll and anything not available there fromm libcmt.lib?
--
- Vince