Page 1 of 1

MemoryError: memory allocation failed, allocating 1584 bytes

Posted: Wed Sep 16, 2015 12:48 pm
by mschulz
Hello,
I have a new Problem, that I do notunderstand.

I get the following error, when I write one more code line, but I think the line is ok. It is equal witch line I write:

Code: Select all

Traceback (most recent call last):
  File "main.py", line 23, in <module>
MemoryError: memory allocation failed, allocating 1584 bytes
Micro Python v1.3.10 on 2015-02-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.

What can I do to solve this error?
Thank you!

Re: MemoryError: memory allocation failed, allocating 1584 bytes

Posted: Wed Sep 16, 2015 12:54 pm
by danicampora
Sharing the piece of code that is causing the exception might be useful, otherwise it is difficult to help you...

Re: MemoryError: memory allocation failed, allocating 1584 bytes

Posted: Wed Sep 16, 2015 1:17 pm
by mschulz
This code runs, but when I uncommand the last line I get the error.

Code: Select all

                pos[0]=abs(F_KE_Rv/F_KE_Rh) # verhältnis Vorn zu Hinten
                if self.__pos_alt[0]>=0 and self.__pos_alt[2]>=0 and self.__pos_alt[4]>=0:
                    pos[0]=(self.__pos_alt[0]+self.__pos_alt[2]+self.__pos_alt[4]+pos[0])/4
                elif self.__pos_alt[0]>=0 and self.__pos_alt[2]>=0:
                    pos[0]=(self.__pos_alt[0]+self.__pos_alt[2]+pos[0])/3
                #elif self.__pos_alt[0]>=0:
                #   pos[0]=(self.__pos_alt[0]+pos[0])/2
               

Re: MemoryError: memory allocation failed, allocating 1584 bytes

Posted: Thu Sep 17, 2015 6:23 am
by pythoncoder
The Pyboard has about 100KB of RAM for heap storage and it looks like your program is using all of it. Floating point maths uses the heap and my guess is that the line of maths you've commented out is trying to allocate memory which is unavailable. In other words the problem isn't with the line of code but with the overall design.

To answer the question of why all the memory is being used or to suggest a fix I think we'd need to see the entire program. Are your arrays large? If so, are they arrays or lists? (Arrays are more memory-efficient).