Reputation: 609
I'm working on a project where I want to implement something like a FORTH interpreter on Arduino. The interpreter consists of "WORDS," where each WORD has a name, a header, and an array of pointers to other WORDS whose definitions it consists of.
There are many standard WORDS that I would like to store in PROGMEM in order to save RAM for user-defined WORDS.
How can I efficiently manage mixed pointers to RAM and PROGMEM in such a system? Specifically, how can I store some data in PROGMEM and point to it while also handling RAM-based data in the same structure?
The struct will look like this:
struct node {
char name[8];
uint8_t flags;
node* ptr_array[]; // e.g. [p0, p1, p2, p3, p4, ...]
// where some pointers (px) point to nodes in RAM,
// and others point to nodes in PROGMEM
};
I’m concerned that I might need to store the type of each pointer (RAM vs PROGMEM) and use that information to choose the correct method when retrieving the value. But I’m not sure how to technically implement this.
Any advice or examples would be greatly appreciated!
Upvotes: 0
Views: 22