what's wrong in my code?!?

A

alessio211734

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.ip=l.end();" code run correcty.
What's wrong?!?



#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.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;
}
 
I

Ian Collins

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.ip=l.end();" code run correcty.
What's wrong?!?


Something with to tool rather than the code? There's nothing in the
code to cause a hang,

If you remove the line that actually does something, how can the code
work correctly??
#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.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

Victor Bazarov

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.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.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
 
J

Juha Nieminen

alessio211734 said:
using namespace std;

Not related to your question, but may I ask what's the purpose of this
line in your example program? You are not using it for anything (as you
shouldn't, really.)

(Where did you learn it anyways?)
 
W

wenxing zheng

There is no any problem in the codes, your question should be related with the DEBUG options.

Please build it with Release Configuration.
 
R

Rox

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.ip=l.end();" code run correcty.
What's wrong?!?



#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.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;
}


the debug version of iterator destructor does some extra work...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top