Mistake on this page?
Report an issue in GitHub or email us

printf and reducing memory

The standard library family of printf (printf, sprintf, fprintf and so on) calls takes a lot of code space. This is because there are multiple format specifiers, and it is not possible to optimize the code at build time. Even a single printf call in your application pulls in the entire standard library.

A solution to reduce code space is to replace the standard printf calls with a smaller implementation.

Mbed OS provides the minimal-printf library, which offers a subset of the printf features (not all format specifiers are supported). You can also achieve further flash savings if your application does not require 64-bit integers or floating point printing.

For a memory footprint comparison between standard printf and minimal-printf, please see our Blinky size comparison.

To further reduce the memory footprint of applications that don't require file handling, enable the system I/O minimal console retarget. You can do this by enabling the configuration parameter platform.stdio-minimal-console-only. Please see the platform configuration reference for more information.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.