I’m opening a text file which can hold anywhere between 100 and 50,000 dataFrames, and assigning each line of the txt file to a dataFrame, where a dataFrame is defined as follows:
typedef struct {
double x;
double y;
double z;
double azimuth;
double elevation;
double roll;
} dataFrame;
I need the data to be accessible so that I can plot it in a graph in qwt, (which means I’ll need to create various other arrays from the data as well for instantaneous velocity etc.) but I’m a bit worried since I don’t know how much this is gonna slow down the system.
Currently, I read the number of lines, and then have
dataFrame* left;
dataFrame* right;
left = new dataFrame[lineCount/2];
right= new dataFrame[lineCount/2];
and then procede to fill it up as the data is read from the txt file.
If you only need fast indexing and you know the number of elements (
lineCount) up front, nothing beats a good old array.*If you also want fast appending, use a dynamic array such as
std::vectororQVector.If you want fast searching for an item by key, check out
std::set,std::map,QSet,QHash.[*] Almost nothing. Post your alternatives in the comments.