Boost Graph Very Strange Behavior
Dear All, I have upgraded to Boost 1.47.0 and I have spent a day on the following strange behavior that someone who knows Boost better may explain to me. Consider the source below. If I uncomment the line: //cout << ""; in line 39, then the program starts working, i.e., it outputs: 0x1 If I comment out line 39, then I get 0 There are no memory leaks. This kind of stuff gives me nightmares. Thanks for your help and sorry for the longish example. Thanks, -- Alex ----------------------------------------------------------------------- #include <boost/graph/adjacency_list.hpp> #include <iostream> using namespace boost; using namespace std; typedef adjacency_list<listS, listS, undirectedS, property<vertex_name_t, void *>, property<edge_name_t, void *> > GraphT; class Graph : public GraphT { public: Graph(); public: typedef graph_traits<GraphT>::vertex_descriptor VertexType; typedef graph_traits<GraphT>::edge_descriptor EdgeType; public: ostream &put(ostream &) const; void setNetLabel(const EdgeType &, void *); void addNet(const VertexType &, const VertexType &, void *); private: property_map<GraphT, edge_name_t>::type net_; }; Graph::Graph() { net_ = get(edge_name, *this); } void Graph::setNetLabel(const EdgeType &edge, void *label) { //cout << ""; net_[edge] = label; } void Graph::addNet(const VertexType &branch1, const VertexType &branch2, void *label) { EdgeType ei; bool inserted; tie(ei, inserted) = add_edge(branch1, branch2, *this); if (inserted) { setNetLabel(ei, label); } } ostream &Graph::put(ostream &out) const { graph_traits<GraphT>::edge_iterator ei, ei_end; for (tie(ei, ei_end) = edges(*this); ei != ei_end; ei++) { out << net_[*ei] << endl; } return out; } int main(int argc, char **argv) { Graph graph; Graph::VertexType v1 = add_vertex(graph); Graph::VertexType v2 = add_vertex(graph); graph.addNet(v1, v2, (void *)1); graph.put(cout); return EXIT_SUCCESS; } -----------------------------------------------------------------------
On Sun, 21 Aug 2011, Alexander Feldman wrote:
Dear All,
I have upgraded to Boost 1.47.0 and I have spent a day on the following strange behavior that someone who knows Boost better may explain to me. Consider the source below. If I uncomment the line:
//cout << "";
in line 39, then the program starts working, i.e., it outputs:
0x1
If I comment out line 39, then I get
0
There are no memory leaks.
This kind of stuff gives me nightmares.
Thanks for your help and sorry for the longish example.
I tried your example with GCC 4.6 on Linux and it worked just fine, both with and without the printout. BTW, it is not recommended to inherit from BGL (or STL) objects since they do not have virtual destructors and are not meant for that usage. -- Jeremiah Willcock
On 08/21/2011 01:03 AM, Jeremiah Willcock wrote:
On Sun, 21 Aug 2011, Alexander Feldman wrote:
Dear All,
I have upgraded to Boost 1.47.0 and I have spent a day on the following strange behavior that someone who knows Boost better may explain to me. Consider the source below. If I uncomment the line:
//cout << "";
in line 39, then the program starts working, i.e., it outputs:
0x1
If I comment out line 39, then I get
0
There are no memory leaks.
This kind of stuff gives me nightmares.
Thanks for your help and sorry for the longish example.
I tried your example with GCC 4.6 on Linux and it worked just fine, both with and without the printout. BTW, it is not recommended to inherit from BGL (or STL) objects since they do not have virtual destructors and are not meant for that usage.
I have just figured out that the problem appears with gcc 4.5.2 -O2 and the program runs fine with -O1. I think now, it is something related to inlining but I will investigate further. Thanks for the advise not inherit from BGL - will change that. Best, -- Alex
-- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Alexander Feldman
-
Jeremiah Willcock