Is this a bug in my code, a bug in the interpreter, or “you can’t do that!”
Given a declaration:
class ParallelCoord : public TObject {
private:
vector<vector* > *parValues;
…
and this code snippet in the constructor:
parValues=new vector<vector >;
while (!pcin.eof())
{ vector v = new vector;
v->reserve(nParameters);
for (int i=0; i<nParameters; i++)
{ double d; pcin>>d; v->push_back(d);
} cout<size()<<"=="<capacity()<<endl;
parValues->push_back(v);
nMembers++;
}
when I execute
root [0] .L ParallelCoord.cxx
root [1] ParallelCoord t;
the printout starts:
0==0
1==1024
2==1024
… on to
1024==1024
at which point root crashes back to the command prompt.
If I add this code before the parValues->push_back() to manually
increase the vector size, the loop runs to completion.
if (parValues->size() == (parValues->capacity()-1))
{ parValues->reserve(parValues->capacity()*2);
cout<<“Increased parValue capacity”<<endl;
}
In other words the vector expands itself to 1024 capacity when the first
element is added, but crashes (when trying to expand?) when adding
the 1025th element; my manual code intervention prevents this. I’m
willing to believe this is a bug in my code, what do the experts think?
Version 5.08/00 13 December 2005
Compiled on 15 December 2005 for win32gcc (downloaded binaries)
Running under cygwin