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. Memory Overrun! in MFC

Memory Overrun! in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelpquestion
17 Posts 6 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.
  • M Offline
    M Offline
    mostafa_pasha
    wrote on last edited by
    #1

    Hi, I have function that i allocate very large data in Heap, after i create with new & use it when i want to delete these , there is memory overrun error & i do not know how can i solve that!

    D Z M 3 Replies Last reply
    0
    • M mostafa_pasha

      Hi, I have function that i allocate very large data in Heap, after i create with new & use it when i want to delete these , there is memory overrun error & i do not know how can i solve that!

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

      mostafa_pasha wrote:

      ...there is memory overrun error...

      What do the new and delete statements look like? Is the pointer returned from new being changed (e.g., incremented?


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      1 Reply Last reply
      0
      • M mostafa_pasha

        Hi, I have function that i allocate very large data in Heap, after i create with new & use it when i want to delete these , there is memory overrun error & i do not know how can i solve that!

        Z Offline
        Z Offline
        Zac Howland
        wrote on last edited by
        #3

        It is hard to help you if you don't at least show the relevant portions of your code.

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        D 1 Reply Last reply
        0
        • Z Zac Howland

          It is hard to help you if you don't at least show the relevant portions of your code.

          If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

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

          Didn't you get the memo, Zac? Today is guess-what's-wrong-with-my-code-without-seeing-it day. ;)


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          Z 1 Reply Last reply
          0
          • M mostafa_pasha

            Hi, I have function that i allocate very large data in Heap, after i create with new & use it when i want to delete these , there is memory overrun error & i do not know how can i solve that!

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            mostafa_pasha wrote:

            there is memory overrun error & i do not know how can i solve that!

            Don't overrun the end of your allocated memory. Mark

            T 1 Reply Last reply
            0
            • D David Crow

              Didn't you get the memo, Zac? Today is guess-what's-wrong-with-my-code-without-seeing-it day. ;)


              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

              "Judge not by the eye but by the heart." - Native American Proverb

              Z Offline
              Z Offline
              Zac Howland
              wrote on last edited by
              #6

              Apparently it fell under the stack of memos reminding me to fill out my damn TPS reports.

              If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

              C 1 Reply Last reply
              0
              • M Mark Salsbery

                mostafa_pasha wrote:

                there is memory overrun error & i do not know how can i solve that!

                Don't overrun the end of your allocated memory. Mark

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

                Mark Salsbery wrote:

                Don't overrun the end of your allocated memory.

                HI Mark,  could you explain it further do you mean something like this    int*  pnSize=new int[10];  pnSize[10]=10;// which is not available   delete [] pnSize;

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

                M 2 Replies Last reply
                0
                • T ThatsAlok

                  Mark Salsbery wrote:

                  Don't overrun the end of your allocated memory.

                  HI Mark,  could you explain it further do you mean something like this    int*  pnSize=new int[10];  pnSize[10]=10;// which is not available   delete [] pnSize;

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  That is extremely well done, yes :) cheers, Mark

                  1 Reply Last reply
                  0
                  • T ThatsAlok

                    Mark Salsbery wrote:

                    Don't overrun the end of your allocated memory.

                    HI Mark,  could you explain it further do you mean something like this    int*  pnSize=new int[10];  pnSize[10]=10;// which is not available   delete [] pnSize;

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    Actually I was wrong about your code being "well done"... The original poster said "i allocate very large data". Therefore, your code sample should be: int* pnSize=new int[100]; pnSize[100]=10;// which is not available delete [] pnSize; :doh: Have a great day, Mark

                    M T 2 Replies Last reply
                    0
                    • M Mark Salsbery

                      Actually I was wrong about your code being "well done"... The original poster said "i allocate very large data". Therefore, your code sample should be: int* pnSize=new int[100]; pnSize[100]=10;// which is not available delete [] pnSize; :doh: Have a great day, Mark

                      M Offline
                      M Offline
                      mostafa_pasha
                      wrote on last edited by
                      #10

                      excuse me for delay to response, //OVERRUN is for Pitch array .... char *BeginFile = NULL; BeginFile = new char[44]; try { File.Read(BeginFile,44); } catch(CFileException *pe) { pe->ReportError(); } DWORD dwLength = (File.GetLength()-44); char *inChar ; inChar = new char[800000]; try { File.Read(inChar,dwLength); } catch(CFileException *pe) { pe->ReportError(); } File.Close(); int tmp; unsigned char c1,c2; double *in ; in = new double[400000]; int smp=dwLength/2; const int fs=22050; const int fc=7500; int kc = floor( (double)(fc * N / fs) )+1; int len=ceil((double)smp/N*2)+1; double *CBn ; CBn = new double[kc*len]; int sizeCB; sizeCB = Netmfile.Feature( in , kc ,smp , CBn ); int *Pitch = NULL; Pitch = new int[3000]; // :wtf:if use 2000 have OVERRUN PROBLEM IF use 3000 DO NOT HAVE OVERRUN PROBLEM:omg: // PitchExtract shown below int LenPitch = Netmfile.PitchExtract( in ,smp ,Pitch ); delete in; delete BeginFile; delete in; delete BeginFile; char weigthpath[]="text\\"; //path of MAT to TXT file double *CB1t ; CB1t = new double [kc*len]; Netmfile.net( CBn , CB1t , kc , weigthpath , sizeCB ); Netmfile.z = sizeCB * N - (sizeCB-1) * (N/2); smp2 = new double [Netmfile.z]; for (i=0 ; iN/2) { for ( j=p ; j>=i+1 ; j--) pichi [ j ] = pichi [ j - 1 ] ; pichi [ i ] = N/2; pichi [ i + 1 ] = m - N/2; m=0; p++; } i++; } return (p); }

                      M D 2 Replies Last reply
                      0
                      • M mostafa_pasha

                        excuse me for delay to response, //OVERRUN is for Pitch array .... char *BeginFile = NULL; BeginFile = new char[44]; try { File.Read(BeginFile,44); } catch(CFileException *pe) { pe->ReportError(); } DWORD dwLength = (File.GetLength()-44); char *inChar ; inChar = new char[800000]; try { File.Read(inChar,dwLength); } catch(CFileException *pe) { pe->ReportError(); } File.Close(); int tmp; unsigned char c1,c2; double *in ; in = new double[400000]; int smp=dwLength/2; const int fs=22050; const int fc=7500; int kc = floor( (double)(fc * N / fs) )+1; int len=ceil((double)smp/N*2)+1; double *CBn ; CBn = new double[kc*len]; int sizeCB; sizeCB = Netmfile.Feature( in , kc ,smp , CBn ); int *Pitch = NULL; Pitch = new int[3000]; // :wtf:if use 2000 have OVERRUN PROBLEM IF use 3000 DO NOT HAVE OVERRUN PROBLEM:omg: // PitchExtract shown below int LenPitch = Netmfile.PitchExtract( in ,smp ,Pitch ); delete in; delete BeginFile; delete in; delete BeginFile; char weigthpath[]="text\\"; //path of MAT to TXT file double *CB1t ; CB1t = new double [kc*len]; Netmfile.net( CBn , CB1t , kc , weigthpath , sizeCB ); Netmfile.z = sizeCB * N - (sizeCB-1) * (N/2); smp2 = new double [Netmfile.z]; for (i=0 ; iN/2) { for ( j=p ; j>=i+1 ; j--) pichi [ j ] = pichi [ j - 1 ] ; pichi [ i ] = N/2; pichi [ i + 1 ] = m - N/2; m=0; p++; } i++; } return (p); }

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #11

                        First of all...what's going on in these sections....you left something out for (i=0 ; i smp2[i]=0; delete CBn; delete CB1t; delete Pitch; // have problem.......................use devpartner say OVERRUN } ... while (i { m=m+pichi[i]; if ... Mark

                        M 1 Reply Last reply
                        0
                        • M Mark Salsbery

                          First of all...what's going on in these sections....you left something out for (i=0 ; i smp2[i]=0; delete CBn; delete CB1t; delete Pitch; // have problem.......................use devpartner say OVERRUN } ... while (i { m=m+pichi[i]; if ... Mark

                          M Offline
                          M Offline
                          mostafa_pasha
                          wrote on last edited by
                          #12

                          excuse me for this fault, i do not know when i ignore HTML tags , the messeage is correct:confused: Netmfile.z = sizeCB * N - (sizeCB-1) * (N/2); //double *smp2; smp2 = new double [Netmfile.z]; for (i=0 ; iN/2) { for ( j=p ; j>=i+1 ; j--) pichi [ j ] = pichi [ j - 1 ] ; pichi [ i ] = N/2; pichi [ i + 1 ] = m - N/2; m=0; p++; //beacause of increase of Pitch length in each atage } i++; } return (p);

                          1 Reply Last reply
                          0
                          • M Mark Salsbery

                            Actually I was wrong about your code being "well done"... The original poster said "i allocate very large data". Therefore, your code sample should be: int* pnSize=new int[100]; pnSize[100]=10;// which is not available delete [] pnSize; :doh: Have a great day, Mark

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

                            Mark Salsbery wrote:

                            The original poster said "i allocate very large data". Therefore, your code sample should be: int* pnSize=new int[100];

                            HE HE HE! :-D

                            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

                            1 Reply Last reply
                            0
                            • M mostafa_pasha

                              excuse me for delay to response, //OVERRUN is for Pitch array .... char *BeginFile = NULL; BeginFile = new char[44]; try { File.Read(BeginFile,44); } catch(CFileException *pe) { pe->ReportError(); } DWORD dwLength = (File.GetLength()-44); char *inChar ; inChar = new char[800000]; try { File.Read(inChar,dwLength); } catch(CFileException *pe) { pe->ReportError(); } File.Close(); int tmp; unsigned char c1,c2; double *in ; in = new double[400000]; int smp=dwLength/2; const int fs=22050; const int fc=7500; int kc = floor( (double)(fc * N / fs) )+1; int len=ceil((double)smp/N*2)+1; double *CBn ; CBn = new double[kc*len]; int sizeCB; sizeCB = Netmfile.Feature( in , kc ,smp , CBn ); int *Pitch = NULL; Pitch = new int[3000]; // :wtf:if use 2000 have OVERRUN PROBLEM IF use 3000 DO NOT HAVE OVERRUN PROBLEM:omg: // PitchExtract shown below int LenPitch = Netmfile.PitchExtract( in ,smp ,Pitch ); delete in; delete BeginFile; delete in; delete BeginFile; char weigthpath[]="text\\"; //path of MAT to TXT file double *CB1t ; CB1t = new double [kc*len]; Netmfile.net( CBn , CB1t , kc , weigthpath , sizeCB ); Netmfile.z = sizeCB * N - (sizeCB-1) * (N/2); smp2 = new double [Netmfile.z]; for (i=0 ; iN/2) { for ( j=p ; j>=i+1 ; j--) pichi [ j ] = pichi [ j - 1 ] ; pichi [ i ] = N/2; pichi [ i + 1 ] = m - N/2; m=0; p++; } i++; } return (p); }

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

                              mostafa_pasha wrote:

                              delete Pitch; // have problem.......................use devpartner say OVERRUN

                              Use delete [] Pitch instead. All new[] must have a matching delete[].


                              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                              "Judge not by the eye but by the heart." - Native American Proverb

                              M 1 Reply Last reply
                              0
                              • D David Crow

                                mostafa_pasha wrote:

                                delete Pitch; // have problem.......................use devpartner say OVERRUN

                                Use delete [] Pitch instead. All new[] must have a matching delete[].


                                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                "Judge not by the eye but by the heart." - Native American Proverb

                                M Offline
                                M Offline
                                mostafa_pasha
                                wrote on last edited by
                                #15

                                Hi, but there is not diffrence , i think before i must use delete [] when i create two dimensional array in heap such as this: vf_Weigth = new float* [nlayer2+1]; for ( i =0 ; i< (nlayer2+1) ; i++) vf_Weigth[i] = new float[nlayer1]; delete [] vf_Weigth; // but now i find i delete in these way: for (int i = 0; i < nlayer2+1 ; i++) delete vf_Weight[i]; is that code is correct? at last i say again delete [] Pitch is not work & my code have that serios error. Best Regards. M.J.M.

                                D 1 Reply Last reply
                                0
                                • M mostafa_pasha

                                  Hi, but there is not diffrence , i think before i must use delete [] when i create two dimensional array in heap such as this: vf_Weigth = new float* [nlayer2+1]; for ( i =0 ; i< (nlayer2+1) ; i++) vf_Weigth[i] = new float[nlayer1]; delete [] vf_Weigth; // but now i find i delete in these way: for (int i = 0; i < nlayer2+1 ; i++) delete vf_Weight[i]; is that code is correct? at last i say again delete [] Pitch is not work & my code have that serios error. Best Regards. M.J.M.

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

                                  You need to gain a further understanding of how new/delete works, specifically with the [] notation. See: http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=36&rl=1[^] http://www.cplusplus.com/doc/tutorial/dynamic.html[^] http://www.glenmccl.com/bett_003.htm[^]


                                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                                  "Judge not by the eye but by the heart." - Native American Proverb

                                  1 Reply Last reply
                                  0
                                  • Z Zac Howland

                                    Apparently it fell under the stack of memos reminding me to fill out my damn TPS reports.

                                    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                                    C Offline
                                    C Offline
                                    charlieg
                                    wrote on last edited by
                                    #17

                                    lol - I LOVE that movie! .... reaching for my red stapler

                                    Charlie Gilley Will program for food... Whoever said children were cheaper by the dozen... lied. My son's PDA is an M249 SAW. My other son commutes in an M1A2 Abrams

                                    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