What exactly is point (or purpose) of using ZeroMemory(), I've noticed that sometimes code uses them and sometimes they don't.
What exactly is point (or purpose) of using ZeroMemory(), I've noticed that sometimes code uses them and sometimes they don't.
This is how I think of it:
When you declare a variable or array etc then it is filled with garbage until you put meaningful data in there. ZeroMemory (or the c memset) simply flatten it all out with zeros (or other character in the case of memset). This is useful for checking contents etc - if they're all zero then you know that object has just been initialised or 'cleared'. Another use as just a plain value is with boolean arrays: it's a quick and painless method to set the values to false.
Last edited by Ken Fitlike; 07-11-2002 at 05:14 PM.
its also saves you time writing stuff, ie. the WNDCLASSEX class has about three or four variables that you set to 0. when you ZeroMemory() it, you wont have to set those variables to 0
"There are three kinds of people in the world...
Those that can count and those that can't."
Totally understand it now, thanks.
On a similar not, the c function calloc will allocate memory and zero it out all in one.