Skip to main content
gamedev.net
🔒 Locked

ZeroMemory!

Started by BlackHwk4 2 replies 500+ views
Original Post
BlackHwk4
BlackHwk4
I remember seeing someone use ZeroMemory somewhere. I think it was in one of the gamedev articles but I haven''t been able to find which one it was yet. I think the comment above it said that it was used to clear the memory. Is it like using memset to clear the memory? Are they the same or is one better to use than the other? Thanks.
AmmoSponge
AmmoSponge
I think in the Game Programming Genesis articles here on Gamedev you saw a macro he made called ZeroMemory. Basically it does exactly what the name says: It fills all the data members with zeros. In a sense it "clears" the memory by replacing whatever junk was in there with zeros. Frankly either I am an idiot and forgot or I just plain dont know what memset is/does. ZeroMemory is good practice for DX objects like DDSURFACEDESC2 that may not have all its fields filled out to replace any junk before you use it (Look in the DX help about DDSURFACEDESC2 if you need to see why you dont fill out all data memebers).
Eraserhead
Eraserhead
ZeroMemory is actually in the Win32 API. Check it out in MSDN. I''d be surprised though, if it isn''t implemented as either a macro for memset, or that it just calls memset directly.
Spartacus
Spartacus
ZeroMemory is just another way of doing this:

DDSURFACEDESC2 ddsd;
memset(&ddsd, 0, sizeof(DDSURFACEDESC2));

With ZeroMemory you could have done it like this:

DDSURFACEDESC2 ddsd;
ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));

So ZeroMemory is just a macro defined like this:

#define ZeroMemory(pnt, size) memset(pnt, 0, size)

That''s it ,

-René
Real programmers don't document, if it was hard to write it should be hard to understand

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.