Re: what's wrong in my code?!?
On 6/26/2012 4:25 AM, alessio211734 wrote:
Hi All,
I execute this code on visual studio 2005 and in debug session my compiler
stay blocked on the return istruction of test function for 50 sec.
If I remove this line "facesAttributes[i].ip=l.end();" code run correcty.
What's wrong?!?
Probably nothing. You have a local vector (as the member of the
'fastMeshAttribute') that has two hundred thousand elements. Each
element likely has a non-trivial destructor, which has to execute when
your 'fast' local variable is destroyed as part of returning from the
'test' function. The debugger is likely doing something (validating
that your iterator member of 'ShortestTriangleAttribute' is still valid
or the like).
When you remove the assignment, the vector elements contain
default-initialized iterators, which are probably easier for your
debugger to dispose of, so it uses less memory.
What is the time difference when you run your program built for
"Release" with and without the line? Also, read up on the debugging
measures Microsoft has for iterators (there are macros that you can
define to disable those measures, not sure whether they are defined when
you don't use a debugging version of the Standard Library), and those
are off-topic, so seek help from the Microsoft online developer forums.
#include<map>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
class ShortestTriangleAttribute
{
public:
std::list<int>::iterator ip;
};
class fastMeshAttribute
{
public:
fastMeshAttribute(){};
fastMeshAttribute(std::list<int> & l)
{
std::list<int>::iterator it;
facesAttributes.resize(200000);
for (int i=0;i<facesAttributes.size();i++)
{
facesAttributes[i].ip=l.end();
}
};
~fastMeshAttribute()
{
int a=0;
};
std::vector<ShortestTriangleAttribute> facesAttributes;
};
bool test()
{
std::list<int> l1;
l1.push_back(1);
l1.push_back(2);
l1.push_back(3);
fastMeshAttribute fast(l1);
return true;
};
int main()
{
test();
return 0;
}
V
--
I do not respond to top-posted replies, please don't ask