c++ - Remove old values in list and add new ones -


i'm not sure how explain properly, let me try. have c++ program listening data on can bus (communication bus vehicles). every 1 second, receive new message off bus contains diagnostic information error messages. message not fixed length, message 1 time may contain 5 faults, , next time may contain 3 faults. message comes 2 (or more) different sources, each 1 of them sends every 1 second. in ui, need display list of active faults cycling through them @ rate of 1 per every 5 seconds.

here's question. how efficiently keep list updated latest information? adding list no problem, how remove item should no longer in list? in other words, if receive 3 faults in message, means 2 of them not exist anymore. thing can come using timestamps , bunch of loops compare 2 messages , add/remove/update list. there more efficient exists sort of thing?

edit: clarify, need remove items list because faults no longer active. if have array follows:

// message received: (psudo code) fault newfaults1[5] { fault1, fault2, fault3, fault4, fault5 }; fault newfaults2[7] { fault1, fault2, fault3, fault4, fault5, fault6, fault7 };  // populate array holds both array values (int = 0;  < newfaults1.count(); i++)     faults[i] = newfaults1[i];  (int = 0; < newfaults2.count(); i++)     faults[i + newfaults1.count()] = newfaults2[i];  // now, next time message received, there fewer faults. fault newfaults1[2] { fault1, fault2 }; fault newfaults2[1] { fault1 };  // todo: how remove of old items in faults array? 

ok, think question might lot simpler first appeared. question seems how resize array?

the simple answer not use array std::vector instead. e.g.

#include <vector> std::vector<fault> faults;  // add fault vector faults.push_back(f);  // remove faults vector faults.clear();  // resize faults vector faults.resize(2);  // size of vector num = faults.size();  // loop through faults (i = 0; < faults.size(); ++i) {     f = faults[i];     // f } 

apologies if i've misunderstood.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -