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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ Memory Problem

  • 15-07-2010 7: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