User`s manual

334 digi.com Hints and Tips
Reduce usage of root constants and string literals
Shortening literal strings and reusing them will save root space. The compiler automatically reuses iden-
tical string literals.
These two statements :
printf (“This is a literal string”);
sprintf (buf, “This is a literal string”);
will share the same literal string space whereas:
sprintf (buf, “this is a literal string”);
will use its own space since the string is different.
Use xdata to declare large tables of initialized data
If you have large tables of initialized data, consider using the keyword xdata to declare them. The disad-
vantage is that data cannot be accessed directly with pointers. The function xmem2root() allows
xdata to be copied to a root buffer when needed.
// This uses root code space
const int root_tbl[8]={300,301,302,103,304,305,306,307};
// This does not
xdata xdata_table {300,301,302,103,304,305,306,307};
main(){
// this only uses temporary stack space
auto int table[8];
xmem2root(table, xdata_table, 16);
// now the xmem data can be accessed via a 16 bit pointer into the table
}
Both methods, const and xdata, create initialized data in flash at compile time, so the data cannot be
rewritten directly.
Use xstring to declare a table of strings
The keyword xstring declares a table of strings in extended flash memory. The disadvantage is that
the strings cannot be accessed directly with pointers, since the table entries are 20-bit physical
addresses. As illustrated above, the function xmem2root() may be used to store the table in tempo-
rary stack space.
// This uses root code space
const char * name[] = {“string_1”, . . . “string_n”};
// This does not
xstring name {“string_1”, . . . “string_n”};
Both methods, const and xstring, create initialized data in flash at compile time, so the data cannot
be rewritten directly.
Turn off selected debugging features
Watch expressions, breakpoints, and single stepping can be selectively disabled on the Debugger tab of
Project Options to save some root code space.