The function gets called very frequently, so I try to lower memory-reallocation etc. What bothers me, is the vector
and int
, though I cant move them outside the function otherwise I get std::bad_alloc
. So far I have:
void callbString(const std_msgs::String::ConstPtr& msg)
{
vector<string> cbstrVec;
int cbtype;
//get string and split into vector
string str = (msg->data.c_str());
if(str.empty()) return;
str.erase(0,1);
boost::split(cbstrVec, str, boost::is_any_of(" "));
stringstream(cbstrVec[2])>>cbtype;
c.setvec(cbstrVec,cbtype); //takes (vector<string>,int)
}