CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Variable pointer vs array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

Variable pointer vs array
PostPosted: Fri May 14, 2004 9:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 14, 2004 10:32 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 14, 2004 10:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 14, 2004 11:17 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group