Thread: Rather newbish question.

  1. #1
    Unregistered
    Guest

    Rather newbish question.

    What exactly is point (or purpose) of using ZeroMemory(), I've noticed that sometimes code uses them and sometimes they don't.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    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."

  4. #4
    Unregistered
    Guest
    Totally understand it now, thanks.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    On a similar not, the c function calloc will allocate memory and zero it out all in one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sainer overly newbish question
    By parrellel in forum C++ Programming
    Replies: 2
    Last Post: 07-09-2003, 09:33 PM
  2. sad overly newbish question on output
    By parrellel in forum C++ Programming
    Replies: 10
    Last Post: 07-07-2003, 10:26 AM
  3. Newbish Question On String Extract
    By JJB in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2003, 09:46 AM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM