Static string storage

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Static string storage

1,182 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Oct 03 19:21:32 MST 2011
On 8-bit AVRs if you declare a static string ie

const char myString[] = "Hello world";

The bytes are stored in flash and then copied to RAM by the startup code. This is presumably because instructions cannot access data in program memory space.

This is a major PITA because is eats RAM for no real reason.

Is this the case with LPC?


EDIT: const added.
______
Rob
0 Kudos
Reply
8 Replies

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Tue Oct 04 03:38:53 MST 2011
All reasonable compilers for LPC1xxx store const by default in Flash (ROM), not in RAM. Period. Your constants will NOT occupy RAM.
0 Kudos
Reply

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Oct 03 21:45:59 MST 2011
OK, thanks guys. I have a project in mind that needs quite large lookup tables and if the LPC worked the same way that I'm used to it would not be a goer.

As you can tell I'm new to LPCs, it will take me a while to get up to speed.

______
Rob
0 Kudos
Reply

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 21:19:41 MST 2011
My Imagecraft AVR Compiler stores constants also in ROM :eek:

And ROM means Flash here, the place where the program is stored.
0 Kudos
Reply

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Mon Oct 03 21:12:43 MST 2011
AVR compilers (most?) require you to use extensions like __flash or PROGMEM in order to place variables in flash.
LPCxpresso allows you to use const to place variables in flash even though technically const as described in the C standard doesn't have anything to do with storage location of variables.
0 Kudos
Reply

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Oct 03 21:07:56 MST 2011

Quote:
set values at compile time and therefore store it in ROM.


Then that's the answer, a const does [B]not[/B] use any RAM. I thought your "yes" was in answer to my first question which was basically "Does it use RAM?"

The GCC compiler for AVRs does, the ROM (actually flash) contents for all const "variables" are copied into RAM at start up.

Now one more question then, when you say "ROM" do you mean EEPROM or flash?

______
Rob
0 Kudos
Reply

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 20:45:49 MST 2011
With constant qualifier compiler will set values at compile time and therefore store it in ROM.

That doesn't 'waste' RAM if you don't need to change this value :)
0 Kudos
Reply

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Oct 03 20:23:27 MST 2011
Yes that's true, I forgot. But on the AVR const does nothing but throw a compiler error if you have code that writes to the variable, it does not cause the storage to be in flash only.

What happens with the LPCs?

Oops, I just noticed you said "yes", so even on the LPCs you loose RAM for no reason.

______
Rob
0 Kudos
Reply

1,121 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 19:31:12 MST 2011
Yes :eek:

In both cases you should try 'const char ...' :)
0 Kudos
Reply