Click here to Skip to main content
15,880,608 members
Articles / Programming Languages / C
Alternative
Tip/Trick

How to zero your memory?

Rate me:
Please Sign up or sign in to vote.
4.25/5 (3 votes)
23 Aug 2011CPOL 9.9K   3
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)


Written By
Software Developer (Senior) Freelancer
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalhow to add the number Pin
Anubhava Dimri11-Nov-11 2:31
Anubhava Dimri11-Nov-11 2:31 
GeneralReason for my vote of 2 This is to dangerous. Another progra... Pin
Martin Richter [rMVP C++]12-Sep-11 19:57
Martin Richter [rMVP C++]12-Sep-11 19:57 
GeneralReason for my vote of 5 Nice one. Pin
Malli_S9-Sep-11 0:32
Malli_S9-Sep-11 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.