OpenFontRender icon indicating copy to clipboard operation
OpenFontRender copied to clipboard

Recommendations for memory use?

Open chconnor opened this issue 1 year ago • 1 comments

Hello!

I noticed that my SRAM drops by about 4k after a single myofr.printf() call (drawing a time to the screen). However, if I repeat that call many times, the SRAM only drops once.

So I assume that it is just a cache in OpenOFR that is caching something the first time? (Edit: I see setCacheSize() which looks useful for this).

Are there any recommendations you can give to protect SRAM? E.g.:

  • is it smart to use the same sized font to avoid needing to render it at different sizes?
  • does it cache per glyph, so that using more varied glyphs will use more memory?
  • do larger font sizes mean more memory use?
  • can the cache be cleared periodically to save SRAM? (Edit: I see setCacheSize() exists to limit cache size)
  • alternately, can the cache be forced to grow to maximum size to guarantee a bound on memory usage? (Edit: I see setCacheSize() exists to limit cache size)

Thanks!

chconnor avatar Jan 14 '24 21:01 chconnor

Hello @chconnor

Depends on the behavior of the FreeType2 library. You can change the size to cache with setCacheSize, but it simply maps the FreeType2 library.

Please see FreeType2 FTC_Manager_New.

I am not aware of all the specific behaviors, but perhaps the answer is as follows.

is it smart to use the same sized font to avoid needing to render it at different sizes?

Probably not necessary

does it cache per glyph, so that using more varied glyphs will use more memory?

Probably YES.

do larger font sizes mean more memory use?

YES, but temporary increase in memory usage for drawing, not caching

can the cache be cleared periodically to save SRAM? (Edit: I see setCacheSize() exists to limit cache size)

Conditionally possible. FreeType provides FTC_Manager_Reset and OpenFontRender calls it in unloadFont. Current implementation requires font loading again.

alternately, can the cache be forced to grow to maximum size to guarantee a bound on memory usage? (Edit: I see setCacheSize() exists to limit cache size)

Use setCacheSize. By default it is set to the minimum cache size.

Thank you. Sorry for the crazy slow response 🙇‍♂️🙇‍♂️🙇‍♂️

takkaO avatar May 08 '24 07:05 takkaO

Appreciate the reply!

chconnor avatar May 08 '24 18:05 chconnor