Heap exception detection-MS-Visual Studio

Source: Internet
Author: User

    • when applying for a heap space from the system, although the programmer does not know the data structure of the heap space, but the system or something (Microsoft can know) knows, so if we need to check the usage exceptions of the heap, we need to use the mechanism provided by Microsoft to check the normal use of the heap, in this way, we can find the illegal use of the heap in the program process and ensure the high quality of our program!
    • the most important function is _ crtcheckmemory () : this function is easy to use. You can call it at the beginning and end of the Code to test the heap exception. The example is as follows:
      #include 
           
             # include 
            
              # include 
             
               # include 
              
                struct TVT {Inti; charc; chara [] ;}; void test () {char * P = new char [4]; Assert (_ crtcheckmemory ()); strcpy (P, "12345"); Assert (_ crtcheckmemory ();} int main () {test (); Return 0 ;} 
              
             
            
           

    • An exception is displayed in the running result. If you select ignore, the following error is displayed:
       // assertion failed: _ crtcheckmemory (), file E: \ code \ Win32 \ test1 \ main. CPP, line 17 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.