Advice: Buffer to Different Variables Quick & Easy?

D

DaVinci

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.
 
N

Nadina

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top