Couple of ZeroMemory questions.

This is a discussion on Couple of ZeroMemory questions. within the Windows Programming forums, part of the Platform Specific Boards category; I've seen alot of ZeroMemory examples, but some of its a bit confusing. Which is the proper (or prefered way) ...

  1. #1
    GaryFr
    Guest

    Couple of ZeroMemory questions.

    I've seen alot of ZeroMemory examples, but some of its a bit confusing.

    Which is the proper (or prefered way) of doing this.

    WNDCLASSEX wc;

    Would it be:

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    or:

    ZeroMemory(&wc, sizeof(wc));

    I've also seen alot of example where the & is left out completely.

    Which way should I be using?

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Code:
    VOID ZeroMemory(
      PVOID Destination,   // address of block to fill with zeros
      DWORD Length         // size, in bytes, of block to fill with zeros
    );
    In your case I'll advise you to use the following syntax:
    Code:
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

  3. #3
    Unregistered
    Guest
    Yet another random response.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I was also wondering about that... when I was taking a class, the instructor said to use this:
    Code:
    memset(&wc, 0, sizeof(wc));
    I've also seen in some odd example this (at least I THINK it was for a WNDCLASSEX):
    Code:
    WNDCLASSEX wc = {0};
    And in yet another:
    Code:
    ZeroMemory(&wc, sizeof(wc));
    WhAt ShOuLd I uSe??!?!?!?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I personally use ZeroMemory() to set any memory to zero. If I need to set some memory to another value (Not real often) I would use memset.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    If you use c++ and the memory is not dynamic you could

    Code:
    UINT mem[50] = {0};

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    I always use memset. Except when using GlobalAlloc which I haven't done much lately. I don't think there's any advantage to GlobalAlloc anymore. it's a relic.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    You could use

    GlobalAlloc() / LocalAlloc() with the GMEM_ZEROINIT flag or

    HeapAlloc() with HEAP_ZERO_MEMORY or

    calloc()

    to set the mem to zero as allocated.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Hershlag
    I always use memset. Except when using GlobalAlloc which I haven't done much lately. I don't think there's any advantage to GlobalAlloc anymore. it's a relic.


    A while back I was doing something in MASM32 and I couldnt use ZeroMemory()..I looked it up in the sdk includes and noticed that ZeroMemory isnt an exported API....its just a define for memset anyway.....so you might as well stick to memset if your happy with it.

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I see so in short, "there are many ways to do it". Thanks everyone
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple of Questions
    By toonlover in forum Windows Programming
    Replies: 10
    Last Post: 07-14-2006, 01:04 AM
  2. Couple of simple directdraw questions.
    By Deo in forum Game Programming
    Replies: 3
    Last Post: 05-25-2005, 07:55 AM
  3. A couple of questions that someone might know the answer to...
    By Finchie_88 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-15-2005, 08:26 AM
  4. Studying for Final, Couple Questions...
    By stewade in forum C Programming
    Replies: 4
    Last Post: 05-10-2004, 05:02 PM
  5. A couple of PowerPoint questions.
    By sean in forum Tech Board
    Replies: 2
    Last Post: 01-27-2003, 04:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21