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. about the access violation error at the malloc sentence

about the access violation error at the malloc sentence

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasedata-structuresquestion
6 Posts 4 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.
  • W Offline
    W Offline
    wendyyue
    wrote on last edited by
    #1

    hi, the complier tell me this error happens at the statement of the malloc sentence, but I wonder how can this happens for this statement AT2[nAT2].itemset=(int *)malloc(sizeof(int)*up->lb[i].itemlen); usually when the pointer points to the invalid error or the array is out of index then this error happens, but now the very strange thing is I have run the program for 40hours then the error jump out? can anyone help me to analyze this error?

    C CPalliniC D 3 Replies Last reply
    0
    • W wendyyue

      hi, the complier tell me this error happens at the statement of the malloc sentence, but I wonder how can this happens for this statement AT2[nAT2].itemset=(int *)malloc(sizeof(int)*up->lb[i].itemlen); usually when the pointer points to the invalid error or the array is out of index then this error happens, but now the very strange thing is I have run the program for 40hours then the error jump out? can anyone help me to analyze this error?

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Use your debugger to check if up is a valid pointer and that i is in the range of the array.

      Cédric Moonen Software developer
      Charting control [v1.3]

      1 Reply Last reply
      0
      • W wendyyue

        hi, the complier tell me this error happens at the statement of the malloc sentence, but I wonder how can this happens for this statement AT2[nAT2].itemset=(int *)malloc(sizeof(int)*up->lb[i].itemlen); usually when the pointer points to the invalid error or the array is out of index then this error happens, but now the very strange thing is I have run the program for 40hours then the error jump out? can anyone help me to analyze this error?

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        wendyyue wrote:

        I have run the program for 40hours then the error jump out?

        It looks like you'll spend a lot of time to find it out. BTW Have you checked if your process wastes memory? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        In testa che avete, signor di Ceprano?

        W 1 Reply Last reply
        0
        • CPalliniC CPallini

          wendyyue wrote:

          I have run the program for 40hours then the error jump out?

          It looks like you'll spend a lot of time to find it out. BTW Have you checked if your process wastes memory? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          W Offline
          W Offline
          wendyyue
          wrote on last edited by
          #4

          yes it does takes me a lot of time. just now I check the call stack find out that there is a problem in the following statement AT1=(int *)malloc(sizeof(int)*100); AT2=(int *)malloc(sizeof(int)*100); the AT1 can get the pointer and a valid value but the AT2 is 0x000000, can it means that the malloc did not allocate the memory for the AT2, because the memory is used up ? I have run it for 40 hours

          CPalliniC 1 Reply Last reply
          0
          • W wendyyue

            yes it does takes me a lot of time. just now I check the call stack find out that there is a problem in the following statement AT1=(int *)malloc(sizeof(int)*100); AT2=(int *)malloc(sizeof(int)*100); the AT1 can get the pointer and a valid value but the AT2 is 0x000000, can it means that the malloc did not allocate the memory for the AT2, because the memory is used up ? I have run it for 40 hours

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            wendyyue wrote:

            can it means that the malloc did not allocate the memory for the AT2, because the memory is used up ?

            Yes, maybe your app is systematically eating up memory (some missing call to free?). :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            • W wendyyue

              hi, the complier tell me this error happens at the statement of the malloc sentence, but I wonder how can this happens for this statement AT2[nAT2].itemset=(int *)malloc(sizeof(int)*up->lb[i].itemlen); usually when the pointer points to the invalid error or the array is out of index then this error happens, but now the very strange thing is I have run the program for 40hours then the error jump out? can anyone help me to analyze this error?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              wendyyue wrote:

              the complier tell me this error happens at the statement of the malloc sentence...I have run the program for 40hours then the error jump out?

              This makes no sense. :confused: If you are running the program, then you cannot have compiler a error. If you have a compiler error, then you are not running the program.

              "Love people and use things, not love things and use people." - Unknown

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              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