Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. funny crash, do you know why?

funny crash, do you know why?

Scheduled Pinned Locked Moved C / C++ / MFC
testingbeta-testingperformancehelpquestion
8 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    includeh10
    wrote on last edited by
    #1

    My app crashed, I did find probrlm point. to simplify code, I add a line inside crashed function for testing:

    BYTE*pp=new BYTE[iSize];

    iSize is an int, if iSize is 1016, the line is OK. if iSize is 1017, the line crashes, that is, the pointer can't be allocated, or pp is NULL. My PC has 2G memory, so memory should be OK. Do you know why? virus? VC problem? Project settings?

    L E S _ A 5 Replies Last reply
    0
    • I includeh10

      My app crashed, I did find probrlm point. to simplify code, I add a line inside crashed function for testing:

      BYTE*pp=new BYTE[iSize];

      iSize is an int, if iSize is 1016, the line is OK. if iSize is 1017, the line crashes, that is, the pointer can't be allocated, or pp is NULL. My PC has 2G memory, so memory should be OK. Do you know why? virus? VC problem? Project settings?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      maybe the statement is executed many times before it crashes your app, as memory is really running low? you should show actual code to get effective help! :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • I includeh10

        My app crashed, I did find probrlm point. to simplify code, I add a line inside crashed function for testing:

        BYTE*pp=new BYTE[iSize];

        iSize is an int, if iSize is 1016, the line is OK. if iSize is 1017, the line crashes, that is, the pointer can't be allocated, or pp is NULL. My PC has 2G memory, so memory should be OK. Do you know why? virus? VC problem? Project settings?

        E Offline
        E Offline
        elchupathingy
        wrote on last edited by
        #3

        If that memory is not free'd then you have introduced a memory leak and as stated above me this could very well be the reason for the crash in that its running out of memory, but more code would help greatly.

        1 Reply Last reply
        0
        • I includeh10

          My app crashed, I did find probrlm point. to simplify code, I add a line inside crashed function for testing:

          BYTE*pp=new BYTE[iSize];

          iSize is an int, if iSize is 1016, the line is OK. if iSize is 1017, the line crashes, that is, the pointer can't be allocated, or pp is NULL. My PC has 2G memory, so memory should be OK. Do you know why? virus? VC problem? Project settings?

          S Offline
          S Offline
          Sauro Viti
          wrote on last edited by
          #4

          includeh10 wrote:

          My PC has 2G memory, so memory should be OK.

          Be aware that each executable file has an header that hold information about the heap commit size and heap reserve size (see /HEAP (Set Heap Size)[^]); the reserve size has the meaning of the maximum stack size that your executable can use, and its default is 1 MB. If you are allocating more than 1 MB (both in a single shot or with multiple allocations), you can get a similar problem; it doesn't matter if your system is equipped with 2 GB.

          1 Reply Last reply
          0
          • I includeh10

            My app crashed, I did find probrlm point. to simplify code, I add a line inside crashed function for testing:

            BYTE*pp=new BYTE[iSize];

            iSize is an int, if iSize is 1016, the line is OK. if iSize is 1017, the line crashes, that is, the pointer can't be allocated, or pp is NULL. My PC has 2G memory, so memory should be OK. Do you know why? virus? VC problem? Project settings?

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            Put the new inside a try/catch block which should give you some more information regarding the crash.

            try
            {
            BYTE*pp=new BYTE[iSize];
            }
            catch (exception& e)
            {
            cout << e.what();
            }

            «_Superman_»
            I love work. It gives me something to do between weekends.

            Microsoft MVP (Visual C++)

            Polymorphism in C

            T A 2 Replies Last reply
            0
            • _ _Superman_

              Put the new inside a try/catch block which should give you some more information regarding the crash.

              try
              {
              BYTE*pp=new BYTE[iSize];
              }
              catch (exception& e)
              {
              cout << e.what();
              }

              «_Superman_»
              I love work. It gives me something to do between weekends.

              Microsoft MVP (Visual C++)

              Polymorphism in C

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              «_Superman_» wrote:

              try { BYTE*pp=new BYTE[iSize];}catch (exception& e){ cout << e.what();}

              It one the correct way to resolve problem, but still there are some exception which can't be handlled by exception block too.

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
              Never mind - my own stupidity is the source of every "problem" - Mixture

              cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

              1 Reply Last reply
              0
              • _ _Superman_

                Put the new inside a try/catch block which should give you some more information regarding the crash.

                try
                {
                BYTE*pp=new BYTE[iSize];
                }
                catch (exception& e)
                {
                cout << e.what();
                }

                «_Superman_»
                I love work. It gives me something to do between weekends.

                Microsoft MVP (Visual C++)

                Polymorphism in C

                A Offline
                A Offline
                Aescleal
                wrote on last edited by
                #7

                Seeing as the man said the pointer was sometimes 0 when it came back from new he's using an antique compiler which doesn't follow the standard (e.g. VC++6). Catching anything isn't going to help here. Cheers, Ash

                1 Reply Last reply
                0
                • I includeh10

                  My app crashed, I did find probrlm point. to simplify code, I add a line inside crashed function for testing:

                  BYTE*pp=new BYTE[iSize];

                  iSize is an int, if iSize is 1016, the line is OK. if iSize is 1017, the line crashes, that is, the pointer can't be allocated, or pp is NULL. My PC has 2G memory, so memory should be OK. Do you know why? virus? VC problem? Project settings?

                  A Offline
                  A Offline
                  Alan Balkany
                  wrote on last edited by
                  #8

                  It could be a symptom of another memory problem elsewhere. Enable memory testing and rerun your program. It could also be (as someone else suggested) a memory leak being repeatedly executed. If so, this one is easy to fix: make the bb variable static and initially NULL. Then if it's not NULL, free it before assigning the new buffer to it.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups