View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
Variable pointer vs array |
Posted: Fri May 14, 2004 9:27 am |
|
|
I want to know what would be better/faster, if I need to send 32 vars/bytes in a row via serial port, is it better to have an array with an indexing variable or I declare all 32 variables and use a pointer to the first var and an indexing variable?
like:
byte index
byte vars[32]
puts(vars[index])
index++
or:
byte pointer
byte index
byte var1
...
...
byte var32
pointer=address of var1
puts(pointer+index)
index++ |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Fri May 14, 2004 10:32 am |
|
|
A pointer to memory is larger than a byte. An array that exist in a simgle bank of memory may use a single byte as an index. You should compile code that does both and compaire the list file. Either way you go it will be much faster than the serial port can send or recieve. |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Fri May 14, 2004 10:48 am |
|
|
It will be implemented using serial interrupts, once one byte is sent, the index is incremented and sent another byte.
I�m new to C, that is why the �pseudo code�, I need to read more about it.
My question is about how to access the values in ram memory. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri May 14, 2004 11:17 am |
|
|
To further muddy the waters, you could use a UNION to access the same memory locations both ways.... _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|