What's the fastest way to implement these functions in C/C++?
I was thinking of something along the lines of:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
std::vector<std::string> header;
std::vector< std::vector<double> > data;
voidregister(std::string name)
{
header.push_back(name);
}
void record()
{
std::vector<double> line;
for (std::vector<std::string>::iterator::it = header.begin();
it!= header.end(); ++it)
{
double value = LuaGet(*it); // double LuaGet(string) returns value of the label
line.push_back(value);
}
data.push_back(line);
}
With all of the dynamic memory allocation, I'm guessing that there's a better way to do this (and make it easy to read in the future). Is there a better way? Since I'll be making plots out of each column, a way which makes it easier to read each series might look like the following (but it makes it harder to align with the other data):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
std::map<std::string, std::vector<double> > data;
voidregister(std::string name)
{
data[name] = NULL;
}
void record()
{
for (std::map<std::string, std::vector<double> >::iterator it = data.begin();
it != data.end(); ++it)
{
double value = LuaGet(it->first);
it->second.push_back(value);
}
}