Dyslexicbloke:
- Use a case statement, there would need to be a case for every variable I want to access.
That seems simple and is probably fast but I doubt its the bast way.
Fast? Probably not. The GCC-AVR compiler that comes with Arduino expands switch/case to a series of if/else.
A simple speed improvement is to put the most likely cases at the top.
- Use a two arrays one hold the place-holder text and a second, with the same ordinal, to hold a pointer to the value.
I could loop through the first until I found the required name and then get the pointer from the second, using it to return the value.
Hashing. Hash function. Hash table.
If you are concerned about look-up performance...
http://burtleburtle.net/bob/hash/perfect.html
How do I go about doing this on an Arduino
a. Getting a pointer to a variable?
& MyVariable;
b. using the pointer to return the variable value
int MyVariable;
void loop( void )
{
int * MyPointer;
MyPointer = & MyVariable;
Serial.println( * MyPointer );
}
Do global variables always stay in the same place in memory once they have been created
Yes.
or do I need to do something to ensure that?
No.