avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Memory Size Report


From: Peter Harrison
Subject: Re: [avr-gcc-list] Memory Size Report
Date: Sun, 05 Feb 2006 21:58:27 +0000
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Ned Konz wrote:

Look at the avr-libc manual; there are provisions for both defining static constants in flash, as well as versions of the stdlib and stdio functions that deal with strings that will work with strings in flash. Look at the documentation for <avr/pgmspace.h>

For instance,

#include <avr/io.h>
#include <avr/pgmspace.h>

const char s1[] = "abc";  /* will take up both RAM and flash */

const char PROGMEM s2[] = "def" /* will take only flash, but you have to use different functions to access it */

then:

char myBuffer[30];    /* in RAM */
sprintf(myBuffer, s1);
/* but */
sprintf_P(myBuffer, s2);


OK - got it I think.

Where I have been in the habit of just writing an explicit string constant in a printf or sprintf call, I should declare the string separately first with the PROGMEM attribute to ensure it does not get copied into RAM at startup...

Seems to do the job.

Bit of a shame as the printing of a message is not as self-documenting if the string is not there in the statement.

I had read the libc manual parts about program space strings as well as noticing the sprintf_P variants. Sadly, my less than nimble brain had not made the right connections.

Pete Harrison







reply via email to

[Prev in Thread] Current Thread [Next in Thread]