Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C

How to zero your memory?

4.25/5 (3 votes)
23 Aug 2011CPOL 10.7K  
I always use a home-made macro to zero my struct's and class's:#define ZEROMEMORY ZeroMemory (this, sizeof (*this))Sample1:struct S1 { double x; long i; char s[255+1]; S1 () { ZEROMEMORY; } };Sample2:class foo { private: double x[16]; char a,b,c; foo () {...
I always use a home-made macro to zero my struct's and class's:
#define ZEROMEMORY ZeroMemory (this, sizeof (*this))

Sample1:

struct S1 { double x; long i; char s[255+1]; S1 () { ZEROMEMORY; } };


Sample2:
class foo {
 private:
   double x[16];
   char a,b,c;
   foo () { ZEROMEMORY; }
};

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)