_crtcheckmemory problem

This is a discussion on _crtcheckmemory problem within the C++ Programming forums, part of the General Programming Boards category; _crtcheckmemory is throwing an exception in my program. I looked it up and saw that it means my debug memory ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    4

    _crtcheckmemory problem

    _crtcheckmemory is throwing an exception in my program. I looked it up and saw that it means my debug memory heap is corrupted.

    I figured I am writing out of array bounds somewhere, but I can't find anywhere that would be happening. Any suggestions about how this could happen, where to look to find the problem, and what to look for would be greatly appreciated as I am totally stumped at this point.

    -Incorect

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Most likely you're writing to memory outside of your address space. You can do this a number of ways, so without seeing the code it will be difficult for us to help you. Just keep plugging away with the debugger. Step through each line and watch your values.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    4
    My program is pretty large at this point and has quite a few source files, I don't know if posting it would be very effeective. I guess what I'm looking for is the different ways this could happen, I have been looking at all my memory manipulation functions, memcpy, memmove, and been looking at my use of [] on arrays, a lot, all this is checking out, what makes this problem hard is that it doesn't always happen. My program will run the same code oh maybe 3000+ times and 5 passes of that code will throw an assert. Nothing about the code is changing in any of those 3000+ passes so I don't know where to look.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    4
    Ok, problem sovled.

    -Incorect

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Ok, problem sovled.
    What was it? Now you have to tell me because you made me write a long debugging post and then delete it.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    4
    This is not my actual code:

    char* pstring2 = new char [strlen(pstring1)];
    strcpy(pstring2, pstring1);

    corrected it with
    char* pstring1 = new char [strlen(pstring2)+1];
    strcpy(pstring2, pstring1);

    I was looking over it because it wasn't anywhere near where the problem was happening, in fact the code wasn't even being run in the loop that was throughing the asserts.

    -Incorect

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I was looking over it because it wasn't anywhere near where the problem was happening
    That's also typical, especially for a fencepost error in an array declaration.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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