Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C++ Memory Problem

  • 15-07-2010 08:56PM
    #1
    Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭


    int** buffer = new int*[2];		// 2 channels
    buffer[0] = new int[fft_size];
    buffer[1] = new int[fft_size];
    
    // zero memory
    zeromem( buffer[0], sizeof(int)*fft_size );
    zeromem( buffer[1], sizeof(int)*fft_size );
    
    // read in data from audio file, perform FFT and store each frame in the container
    for( long offset = 0; offset < reader->lengthInSamples; offset += fft_size ) 
    {
    	FFT_Frame frame( fft_size );
    	reader->read( buffer, 1, offset, fft_size, false );
    	FFT( frame, -1, fft_size, (float*)buffer[0] );	// left channel	
    	frames.add( frame );
    }
    
    delete buffer[0]; buffer[0] = 0;   // throws error here
    delete buffer[1]; buffer[1] = 0;
    delete [] buffer;
    

    Hey, been stuck on a problem for a while. When it reaches the first delete, it throws a "_Block_Type_Is_Valid (pHead->nBlockUse)" error. From what I read on google, the error is usually cause by deleting something twice but I'm zeroing the pointers so I'm not sure why its happening.

    The reader->read() function only takes int** as the buffer type.

    Can anyone see anything wrong with the code? I have the feeling I'm doing something stupid...


Comments

  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭Anima


    Bah typical. Figured it out after posting this. The FFT function was doing something funny. Nevermind.


  • Registered Users, Registered Users 2 Posts: 35 Lexor


    I commented out the loop in your code and everything gets deleted fine (as expected). Can you supply a bit more code for what happens inside your FFT_Frame and FFT constructors and your reader->read(...) function?


  • Registered Users, Registered Users 2 Posts: 35 Lexor


    Cool...


  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭Anima


    Yeah I did the same, thats when I realised it was one of the functions causing the problem. Thanks for having a look anyways.


Advertisement