View previous topic :: View next topic |
Author |
Message |
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
Array of Strings in CCS |
Posted: Wed Sep 01, 2004 10:41 pm |
|
|
I realize CCS does not allow pointers to const data, so I can't do an array of pointers to strings in CCS (at least I haven't been able to so far), but just doing a 2 dimentional array of characters seems to be extremely inefficient. It looks like CCS is taking two bytes of ram per character to preinitialize a "char name[10][10] = (ten strings inserted here); type of array. Are there any tricks to increase efficiency and ram space for strings? It seems like you need to always copy the const string to ram before using it. I did see the "trick" of CCS being able to use a const array of chars as a parameter for a function that takes a char as a parameter and it calls it for each char in the string....
I'm guessing this is device independent and compiler independent as far as I have hear...
I have it working, but just looking to get it working with less ram or an easier way.
If you know of something, I would really appreciate knowing...
Thanks! |
|
|
Guest
|
|
Posted: Thu Sep 02, 2004 2:20 am |
|
|
In a recent project I use this:
typedef struct {
char line[16];
} dLine;
const dLine DisplayMsg[] = { // store in ROM
{"Init modem"},
{"Dialing modem"},
{"Connecting PPP"},
{"Disconnect PPP"},
{"Disconnect line"},
};
void ShowMsg(char be)
{
char j,v;
WriteDisplayData('\n'); // go to the 2nd line of LCD
for (j=0;j<16;j++) {
if (!v) break; // end of line has reached
v = DisplayMsg[be].line[j];
WriteDisplayData(v);
}
} |
|
|
Guest
|
|
Posted: Thu Sep 02, 2004 2:22 am |
|
|
Copy-paste error, sorry:
for (j=0;j<16;j++) {
v = DisplayMsg[be].line[j];
if (!v) break; // end of line has reached
WriteDisplayData(v);
} |
|
|
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
|
Posted: Thu Sep 02, 2004 8:54 am |
|
|
Thanks for the reply -
I changed it to:
for (i=0; i < CMD_NUM_CMDS; i++)
{
strcpy ( strTmp, CmdHandlerStr[i] );
if (strcmp( cmd, strTmp ) == 0)
{
Cmd_Execute( i, ptrArgs );
found = 1;
break;
}
}
such that CmdHandlerStr is defined as:
const char CmdHandlerStr[16][10] = { insert strings here };
and strTmp is defined as: char strTmp[16];
So I just do a strcpy() of each string from Rom/flash to Ram. Couldn't figure out why the strings in ram were taking 2 bytes per char though - that's weird to me... |
|
|
|