Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ Memory Problem

Options
  • 15-07-2010 8:56pm
    #1
    Registered Users 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 Posts: 3,945 ✭✭✭Anima


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


  • Registered Users 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 Posts: 35 Lexor


    Cool...


  • Registered Users 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