fprintf and other ways to kill RAM

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it just me, or when i write say:
fprintf(lcd,"PING!!!NY!!!");
when compiled gcc stores the string into the ram, although the the constant is used only once, the string remains in the ram , for the rest of eternity(or until shutdown/reset)? is there any way to use ram normally?

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This has nothing to do with fprintf().

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so constants in general?

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The avr-libc documentation would explain the use of fprintf_P and the PSTR() macro.

The result could be an fprintf_P(lcd, PSTR("Your string"));

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> so constants in general?

String literals in general.

This is the only way on a Harvard machine to store a string
literal in a way that makes it compliant to the standard so they
can be passed to standard functions (like those from ).

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

isnt there a way at least to optimize it? I have to read string out of the eeprom now, cause i needed all the ram i could get on M162.

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

String literals can be stored in SRAM (default), or in EEPROM or Flash using variable attributes.

In addition to the standard string utilities in , there are program-space optimized string utilities in .

These utilities will allow you to do all the same things as the standard string utilities, except that the literals (format strings, etc...) can be taken directly out of Flash instead of using RAM as a go-between.

Mr MIC wrote:
The avr-libc documentation would explain the use of fprintf_P and the PSTR() macro.