0

I'm working on a C++ project using a FRDM-KL25Z board to measure vibration. My code is working but I need it running on a loop. I'm having problems with memory, I don't have enough space to store the values twice. I used free() commands but even that I'm nothing get all my memory back. Someone knows how to clean all memory used by kiss-fft? It doesn't have a free function, or at list the one that it has doesn't work properly.

I have enough memory to run it just once and show the results. I was trying to do a loop with this function but even using free command I'm nothing getting my initial memory back.

{

void TestFftReal(const char* title, const kiss_fft_scalar in[L], kiss_fft_cpx out[L / 2 + 1])
  kiss_fftr_cfg cfg;
  cfg = kiss_fftr_alloc(L, 0/*is_inverse_fft*/, NULL, NULL);

  if (cfg != NULL) {
      size_t i;
      kiss_fftr(cfg, in, out);
      free(cfg);
  /// Do stuff ///
  } else {
     printf("Not enough memory.\n");
      exit(-1);
  } 
}
Martin Thompson
  • 16,395
  • 1
  • 38
  • 56
Will
  • 804
  • 2
  • 8
  • 17
  • You're going to need to give us more information to go on other than "I'm not getting my memory back." Do you have some code snippets (not your entire codebase, just relevant parts) that would help demonstrate the problem? How can you have enough room to do the FFT but not store the answers? Etc... – Ross Jul 07 '14 at 21:42

1 Answers1

2

The file kiss_fft.h lists a switch called KISS_FFT_USE_ALLOCA. If you define this macro while compiling, then the needed memory is allocated on the stack instead of using malloc. It is automatically freed when the function ends.

You will have to write your loop body to contain a function to allocate the space and run the fft, so that it returns (and frees the space) before the next loop iteration.

UncleO
  • 8,299
  • 21
  • 29
  • Thanks UncleO. Actually the problem was way easier to solve. I was using cout<< to print out my informations. For some reason it was occuping all my memory. I just changed the command to printf and now it works fine! (I just spent 2 days to figure this out hahaha) – Will Jul 14 '14 at 19:38