Sign in to follow this  
Hoggel

Difference between ZeroMemory and memset

Recommended Posts

Hi.

Let's say we have a window class of the type WNDCLASSEX named wc, is there any difference between writing:
memset(&wc, 0, sizeof(wc));
and
ZeroMemory(&wc, sizeof(wc));

Share this post


Link to post
Share on other sites
From whatever version of the Windows SDK is sitting on my computer:

Line 106 of WinBase.h:

#define ZeroMemory RtlZeroMemory

Line 13058 of WinNT.h:

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

Share this post


Link to post
Share on other sites
The reason I heard it exists is because the Windows API code samples, while written primarily in C, were expected to be used as code examples for people using other programming languages. So rather than expecting a Pascal programmer to know that the {} initializer zeros values or what the C standard library function memset() does, they introduced a function that clearly describes what the intended effect is.

Share this post


Link to post
Share on other sites
RtlZeroMemory and memset are both exported by ntdll.dll, at least on the version of ntdll.dll on my machine. Perhaps the one wraps a call to the other as with the macro.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this