문제

I have post here ,a function that i use , to get the accelerator fft .

Setup the accelerator framework for fft on the iPhone

It is working great. The thing is, that i use it in real time, so for each new audio buffer i call this function with the new buffer.

I get a memory warning because of these lines (probably)

A.realp = (float *) malloc(nOver2 * sizeof(float));
 A.imagp = (float *) malloc(nOver2 * sizeof(float));

questions :

  • do i have another way, but to malloc them again and again(dont forget i have to feed it with a new buffer many times a second )

  • how exactly do i free them? (code lines)

  • can it caused by the fact that the fft is heavy to the system ?

Any way to get rid of this warning will help me a lot .

Thanks a lot.

도움이 되었습니까?

해결책

These things should be done once, at the start of your program:

  • Allocate memory for buffers, using code like float *buffer = malloc(NumberOfElements * sizeof *buffer);.
  • Create an FFT setup, using code like FFTSetup setup = vDSP_create_fftsetup(log2n, FFT_RADIX2);.
  • Also test the return values. If malloc or vDSP_create_fftsetup returns 0, write an error message and exit the program or take other exception behavior.

These things should be done once, at the end of your program:

  • Destroy the FFT setup, using code like vDSP_destroy_fftsetup(setup);.
  • Release the memory for the buffers, using code like free(buffer);.

In the middle of your program, while you are processing samples, the code should use the existing buffers and setup. So the variables pointing to the buffers and the setup must be visible to that code. You can either pass them in as parameters (perhaps grouped together in a struct) or make them global (which should be only a temporary solution for small programs).

Your program should be arranged so that it is never necessary to allocate memory or create an FFT setup while samples are being processed.

All memory that is allocated should be freed eventually.

다른 팁

If you are malloc'ing and never freeing, you will run out of memory. Make sure to 'free' your memory using free().

*Note: free() doesn't actually erase any memory. It simply tells the system that we're done with the memory and it's available for other allocations.

// Example:

// allocating memory
int *intpointer;
intpointer = malloc(sizeof(int));

// ... do stuff...

// 'Freeing' it when you are done
free(intpointer);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top