read doubles-containing file with sstream, optimization

Hi everyone,

I have a really big speed problem here. I read a file of let us say 1 million lines with 16 doubles per line. UserClass works as a data container with UserClass::Switch(int ) changing the internal subcontainer's pointer, I believe it should be reasonably fast as it is in various other massive runs. However, I have doubts about creating and destroying stringstream unit (ss), the problem was: after I extract data from ss via ss >>, operator >> stucks and introducing new string ss.string("new strig") doesn't reload operator >>, thus it gives the same last output from the first run all the time. So I chose a longer route via pointers, which, I do believe, causes a serious drop in performance (20 min per 1M x 16 doubles string).

Piece of code:

vector<string> Data=Read_File_VectorString(file);
stringstream *ss;
double out;
UserClass WorkingData;
unsigned int i2=0;
for(unsigned long counter=0; counter < Data.size(); counter++)
{
ss=new stringstream;
*ss << Data[counter];
for(unsigned int i=0; i < 16; i++)
{
*ss >> out;
if( i < 4) {WorkingData.Switch(0); i2=0;}
if( i > 3 && i < 8) {WorkingData.Switch(1); i2=1;}
if( i > 7 && i < 12) {WorkingData.Switch(2); i2=2;}
if( i > 11) {WorkingData.Switch(3); i2=3;}
WorkingData[i-4*i2].push_back(out);
}

delete ss;
}

-------

Please, any comments, suggestions?
At a minimum you can avoid the overhead of a million new and deletes by not making ss a pointer but rather
a stack instance.
That's right. I wanted to do that in the first place. However, I am unable to do that technically. For example, let me have two strings Data[0]="1111 2222 3333"; Data[1]="4444 5555 6666". If I put cout << out << endl; after push_back(out) (assuming that stringstream ss is not a pointer any more, accordingly ss <<, ss >>, i < 4, etc. ); I will get the following:
1111
2222
3333
3333
3333
3333

Operator's >> buffer is stuck with the last value of the first string. That was the problem that made me use a pointer instead. Even though I reset the ss.str(""); ss.str(Data[1]), the buffer is still stuck with the last value, i.e., 3333. I tried playing with ss.seekg() and others with no success.
Topic archived. No new replies allowed.