Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 9, 2012, 10:41 AM   #1
datscha
macrumors newbie
 
Join Date: Jan 2012
Malloc - Incorrect Checksum for Freed Object

Hi all,

Still working on the same project, I have an error I never had before.

Code:
Complex* fft(Complex* x)
{
    int N = sizeof(x)/sizeof(double);
    Complex *w_out;
    w_out = (Complex*) calloc(sizeof(Complex), N);
    
    
    fftw_complex *in, *out;
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    
    fftw_plan p;
    
    for (int j = 0; j < N; j++)
    {
        in[j][0] = x[j].GetReal();
        in[j][1] = x[j].GetImaginary();
    }
    
    p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    
    fftw_execute(p);
    
    for (int i = 0; i < N; i++)
    {
        w_out[i].SetReal(out[i][0]);
        w_out[i].SetImaginary(out[i][1]);
        
    }
    fftw_destroy_plan(p);
    fftw_free(in); fftw_free(out);
    
    return w_out;
}
Above is the call from the Fast Fourier Transform, adapted to my program (cf. previous thread for the Complex class) and based on FFTW3 libraries.

Further in my program, I call this function several times.
One time in a function called fftMethod and two other times for frfftMethod.
If the call is straight forward
Code:
 y = fft(x);
and works fine for the fftMethod. It returns me this weird looking Malloc error for the frfftMethod which obviously comes from the fftw_free commands.
Of course when I try to remove those commands, I get a segmentation fault error.

So if you guys have any idea of what might be wrong, I'm pretty stuck here.

D.


PS: I have a reasonable doubt concerning my declaration of int N in my fft function, but didn't seem to be a problem before.
datscha is offline   0 Reply With Quote
Old Feb 9, 2012, 11:07 AM   #2
datscha
Thread Starter
macrumors newbie
 
Join Date: Jan 2012
Shame on me.

Quote:
PS: I have a reasonable doubt concerning my declaration of int N in my fft function, but didn't seem to be a problem before.
Looks like it didn't like this kind of definition.

My bad for the useless post!

Newbie inside, bear with me
datscha is offline   0 Reply With Quote
Old Feb 13, 2012, 02:30 AM   #3
Sander
macrumors 6502
 
Join Date: Apr 2008
So how did you solve this? Did you decide to make your fft() function take a std::vector of Complex?

By the way, is there a reason you're not using the C++ std::complex data type?
Sander is offline   0 Reply With Quote
Old Feb 13, 2012, 03:23 AM   #4
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by Sander View Post
So how did you solve this? Did you decide to make your fft() function take a std::vector of Complex?

By the way, is there a reason you're not using the C++ std::complex data type?
Look at the line where N is calculated.
gnasher729 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: How do I convert an NSData object to an NSDictionary object, and vice versa? moonman239 iPhone/iPad Programming 6 May 2, 2014 01:17 PM
Upgrade freed up 20gb of space, normal? Fernandez21 OS X Mavericks (10.9) 1 Oct 23, 2013 07:12 AM
Invalid Checksum jpeso2525 iOS 7 2 Jul 28, 2013 10:44 PM
When deleting photos no space is freed up? WouterDS iPhone 3 Oct 20, 2012 09:45 AM
malloc error farmerdoug iPhone/iPad Programming 16 Sep 21, 2012 11:42 AM

Forum Jump

All times are GMT -5. The time now is 11:10 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC