2www.rabbit.com TN219
• Use xdata to declare large tables of initialized data
If you have lar ge tables of initiali zed data, consider using the keyword xdata to declare them.
The disadvantage 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_table[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 temporary 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
Starting with Dynamic C 7.20, watch expressions, breakpoints, and single-stepping can be
selectively disabled to save some root code space. From Dynamic C’s main menu, select
“Options” and then “Project Options.” Look on the Debugger tab in the resulting Options dia-
log.