By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

Advice: Buffer to Different Variables Quick & Easy?

P: n/a
I did a google web & group search and didn't find an answer to my
question so... here we go. Will try to keep it short. (I am not a
complete beginner but am still pretty low on the food chain).

Two programs on two different machines. Program 1 is given values for
multiple variables. Program 1 then sends everything to Program 2 in an
ascii character format. Program 2 then needs to parse the input
buffer, extract the type of data and value, and set its own variables.

I need to keep speed in mind at all times because there will be large
amounts of data to process. I will also be dealing with the same
variables each cycle and I know all of them in advance. They could
change from time to time so I do not want to base the data on specific
locations in the buffer. Also, some may not be present on each cycle.

I could bring in a certain number of characters, say the first three
will specify what the data is, and use an if statement to see what it
is and then assign the numbers after it to a variable. However, this
seems really long and slow and they has got to be a better way.

Using either #define or an enum, I could specify in program 2 all the
data types that it may find in the string and when I send everything
from program 1, I can have it put a : between then so it will be
easier to parse.

Example: Sending VEL=500:TEL=400:SEL=300: into program 2.

Q1: I could setup something (enum, typedef, ??) to bind VEL to a
variable named Vello, TEL to tello, and SEL to sello. What is the best
way to do that for readability and speed?

Q2: Now that I have the specifiers in the buffer linked to a variable
in the program, what would be the fastest way to get the values into
the variables (match them up)? With the knowledge I have now I could
make a for loop with an if loop to check each part of the buffer as it
is read and compare the parts coming in with the pre-defined variables
and then store the variable (via pointer as it will not be local to
the function). But again, there has got to be a faster / better
method.

Thanks for any advice.
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi

Q1:
If you use teh enum, what would happen is instead of sending a 3 letter
code per item you would send a number = essentially an array of chars.

If you have under 100 categories, then using numbers instead of the 3
letter code will help you.

Q2:
How about not sending teh category with each single item but rather
sort the items by category and then send something of the form:

vel,5,500, 44,234,1,3:tel,2,213,2:sel,1,300

code1, num_items, item1, item2, item3...:code2...

Good luck,
Nadina

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.