[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] string initialization using "" and { }
From: |
Stu Bell |
Subject: |
RE: [avr-gcc-list] string initialization using "" and { } |
Date: |
Wed, 27 May 2009 15:35:50 -0600 |
> The "constant initialiser" is stored in initialised .data.
> I.e. it eats FLASH (as the .data initialiser), precious .data
> RAM, and of coursre the RAM in stack when actually used.
>
> I was playing with initialised local arrays a few days ago
> and found out, that avr-gcc performs this same pessimisation
> for any initialised local array, whose initialiser is other
> than 1, 2 or 4 bytes long.
>
> Got the pattern?
>
> It's much better if such array is initialised
> element-by-element: the ldi/st pattern wastes FLASH rather than RAM.
>
> I would submit a request for enhancement, but was recently
> pointed out by the seasoned avr-gcc developers, that there's
> no reason in submitting RFEs without simultaneously providing
> a patch...
I suppose the proper question here is "what are you using the array
for?" If you are using it for parsing strings (comparing to a constant
string, which is what Zoran appears to be doing), you could use the
PROGMEM attribute (or PSTR) for the constant string and the strncmp_P()
function to call the constant string straight out of flash:
char foo[128];
. . .
if ( strncmp_P( foo, PSTR( "abd" ), 3 ) == 0 )
{. . .
I would need to look at the implementation of strncmp_P to decide if
this is as efficient as Jan would like.
Best regards,
Stu Bell
DataPlay (DPHI, Inc.)