That's surprising. Can you elaborate on why this is so?deshipu wrote:I'm afraid const() will only save memory when used within the same module. If you use it from another module, it has to live in memory.
MemoryError when importing a custom module
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: MemoryError when importing a custom module
Re: MemoryError when importing a custom module
Because the const() optimization happens at the compile time, see: http://forum.micropython.org/viewtopic. ... onst#p2561SpotlightKid wrote:That's surprising. Can you elaborate on why this is so?deshipu wrote:I'm afraid const() will only save memory when used within the same module. If you use it from another module, it has to live in memory.
Actually, after re-reading that, I think that it won't save any memory at all in either case.
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: MemoryError when importing a custom module
So, if I want to put constant definitions in a separate module, to be imported by my other modules or main program, "const" won't be of any use to me at all? That's unfortunate, because it puts a penalty on modularizing the code.
Re: MemoryError when importing a custom module
This won't help - MicroPython heap, used for Python objects, and OS heap, used largely for networking-related activity, are separate. This is both good and bad. Good because out-of-memory situation in one won't affect another (well, OOM in OS heap can easily lead to system crash), bad, because a particular application may get not as much memory as it could otherwise. Given that we're trying to get more reliability from ESP8266 (which is otherwise pretty buggy), the choice is obvious.deshipu wrote:maybe by also deactivating the AP/STA interfaces -- whichever you are not using.
@deshipu, @platforma please mind the above and help spread the word.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: MemoryError when importing a custom module
In the meantime, I bumped uPy heap size in the master to 28K as I suggested in another topic. Note that this leaves ~24K after filesystem mount (it requires 4K buffer). That should give a hint how to get more memory for an adhoc application - don't mount filesystem, put your code in frozen modules, start from _boot.py.
Please test networking functionality with the above heap size and share experiences (then also repeat with 32K).
Please test networking functionality with the above heap size and share experiences (then also repeat with 32K).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: MemoryError when importing a custom module
Thanks for correction. I had the impression that before connecting to my wifi the esp had more ram available, but that might as well have been the result of the fact that it was the first boot after flashing. I suppose that when things stabilize a little, I should try and do some experiments determining what helps the memory use and what doesn't.pfalcon wrote:This won't help - MicroPython heap, used for Python objects, and OS heap, used largely for networking-related activity, are separate.deshipu wrote:maybe by also deactivating the AP/STA interfaces -- whichever you are not using.
Re: MemoryError when importing a custom module
Dear Paul,
Thank you for the explanation on the two heaps being separated.
I will try to compile the master and see if the increase in RAM is enough for me to load my modules.
@Deshipu : and now I understand better why const() does not really help here, thank you.
Llwy
Thank you for the explanation on the two heaps being separated.
I will try to compile the master and see if the increase in RAM is enough for me to load my modules.
@Deshipu : and now I understand better why const() does not really help here, thank you.
Llwy
Re: MemoryError when importing a custom module
Thanks Paul. That's good to know, will take this into account.
Re: MemoryError when importing a custom module
Again - are there any plans to support pre-compiled bytcode, e.g. the output of mpy-cross? That would also help to deal with memory shortage. Most of the time, it's the compile phase which fails.
Re: MemoryError when importing a custom module
Please do. There were further changes to optimize memory usage.Llwy wrote: I will try to compile the master and see if the increase in RAM is enough for me to load my modules.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/