Memory Allocation Failed



  • I'm currently trying to use the WiPy 2.0 to run a Fast Fourier transform on around 1000 points. Because NumPy is not available in Pymakr, I wrote an FFT function using recursion. It works fairly well on a list of 512 points. However, when I increase the list to 1024 points and call my FFT function, I run into memory allocation errors within the function. Specifically, the error is "MemoryError: memory allocation failed, allocating 512 bytes".

    Is there anything I can do to fix this memory allocation problem? Does anyone have suggestions on a different implementation to perform an FFT that will use less memory?

    Any suggestions would be greatly appreciated, thanks!



  • @pwest memory is even lower. They have about 40k heap for Python objects, including the byte code.



  • @robert-hh

    Thanks for the input. Speed matters, but even a slow FFT would be useful, at least for proof of concept, sensitivity and calibration. Unfortunately, I've got several WiPy 2.0 boards, which I understand only have 512kb of memory.



  • @pwest Using a PyCom module with 4MB RAM, you should be able to use a standard python implementation, if the speed does not matter.. A search on the Internet reveals standalone implementations not based on NumPy,



  • I desire to use an FFT in an application that I'm working on and I am amazed to find that a search of this entire forum reveals this post as the only one containing 'FFT'. The single reply vectoring me to the excellent work of Peter Hinch leads me to this dialog: https://github.com/peterhinch/micropython-fft/issues/1 where the topic of getting a fast FFT on the ESP32 is discussed, ultimately with a bleak outlook.

    Any advice on how to proceed would be appreciated.



  • @anikamanzo If you do not run the most recent version of the firmware, load that. The available stack was increased in version 1.6.9. You may also try to execute a gc.collect() at various points in your code, e.g. before you create larger memory objects. Besides that, you may look at other non-recursive implementations, like this one:
    https://github.com/peterhinch/micropython-fourier
    It uses ARM assembler in the core fucntions, but Peter also talks about a pure python implementation he tested. So you may address Peter directly and ask for a copy.



Pycom on Twitter