Chris@19: Chris@19: Chris@19: Memory Allocation - FFTW 3.3.4 Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19:
Chris@19: Chris@19:

Chris@19: Previous: Precision, Chris@19: Up: Data Types and Files Chris@19:


Chris@19:
Chris@19: Chris@19:

4.1.3 Memory Allocation

Chris@19: Chris@19:
     void *fftw_malloc(size_t n);
Chris@19:      void fftw_free(void *p);
Chris@19: 
Chris@19:

Chris@19: These are functions that behave identically to malloc and Chris@19: free, except that they guarantee that the returned pointer obeys Chris@19: any special alignment restrictions imposed by any algorithm in FFTW Chris@19: (e.g. for SIMD acceleration). See SIMD alignment and fftw_malloc. Chris@19: Chris@19: Chris@19:

Data allocated by fftw_malloc must be deallocated by Chris@19: fftw_free and not by the ordinary free. Chris@19: Chris@19:

These routines simply call through to your operating system's Chris@19: malloc or, if necessary, its aligned equivalent Chris@19: (e.g. memalign), so you normally need not worry about any Chris@19: significant time or space overhead. You are not required to use Chris@19: them to allocate your data, but we strongly recommend it. Chris@19: Chris@19:

Note: in C++, just as with ordinary malloc, you must typecast Chris@19: the output of fftw_malloc to whatever pointer type you are Chris@19: allocating. Chris@19: Chris@19: Chris@19:

We also provide the following two convenience functions to allocate Chris@19: real and complex arrays with n elements, which are equivalent Chris@19: to (double *) fftw_malloc(sizeof(double) * n) and Chris@19: (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * n), Chris@19: respectively: Chris@19: Chris@19:

     double *fftw_alloc_real(size_t n);
Chris@19:      fftw_complex *fftw_alloc_complex(size_t n);
Chris@19: 
Chris@19:

Chris@19: The equivalent functions in other precisions allocate arrays of n Chris@19: elements in that precision. e.g. fftwf_alloc_real(n) is Chris@19: equivalent to (float *) fftwf_malloc(sizeof(float) * n). Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: