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.
Help needed for beginner - memory alloc and classes
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Help needed for beginner - memory alloc and classes
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.
Index to my micropython libraries.
Re: Help needed for beginner - memory alloc and classes
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.pythoncoder wrote: ↑Mon Apr 26, 2021 4:46 pmThe 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.