Help needed for beginner - memory alloc and classes

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Help needed for beginner - memory alloc and classes

Post by stijn » Mon Apr 26, 2021 3:26 pm

If I'm not mistaken mem_free returns the total free amount not considering memory fragmentation, which would explain the mismatch between free amount and what you can allocate. Moreover file size is not the same as amount of memory needed to store python objects represented in a file. Also it's possible it actually goes out of memory during the parsing of the file. That last bit might very well be why mpy-cross works for you. Note there's also the micropython.mem_info(1) function which shows what is actually going on on the heap. If you search the forum for 'mem_info' that should come up with more explanation.

The Writer class hardly has any member variables so I don't think using it more than once is actually a problem.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Help needed for beginner - memory alloc and classes

Post by pythoncoder » Mon Apr 26, 2021 4:46 pm

The way to save RAM with Python font files is to freeze them as bytecode. That way they use almost zero RAM because the individual glyphs are loaded directly from Flash. This does involve building the firmware yourself.
Peter Hinch
Index to my micropython libraries.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Help needed for beginner - memory alloc and classes

Post by stijn » Tue Apr 27, 2021 8:34 am

pythoncoder wrote:
Mon Apr 26, 2021 4:46 pm
The way to save RAM with Python font files is to freeze them as bytecode. That way they use almost zero RAM because the individual glyphs are loaded directly from Flash. This does involve building the firmware yourself.
We really reallly need sticky posts for things like this. When writing my reply I was sure that I saw something like this already but couldn't immediately find it because I didn't know what to look for exactly.

Post Reply