[pgrouting-dev] Fixes for Bidirectional code just checked in

Stephen Woodbridge woodbri at swoodbridge.com
Sat Jun 1 11:13:49 PDT 2013


Hi all,

I think I have just submitted changes to the bidirectional dijkstra and 
astar routines the resolve the server crashes we were seeing. This 
closes on major outstanding bug against 2.0.

Razequl,

I made two simple changes to your code BiDirDijkstra.cpp and the astar 
version:

1. in BiDirDijkstra::initall I add:
     m_vecNodeVector.reserve(maxNode + 1);

2. in BiDirDijkstra::bidir_dijkstra I move the call to initall(maxNode); 
to before construct_graph(edges, edge_count, maxNode);

This does two major things:

1. std::vector doubles the size of the array every time it needs to 
increase its size and then needs to copy the old data to the new area.

2. reserve() pre allocates all the memory we need once, which avoid 
realloc memory fragmentation and avoids the copy each time it reallocs 
so this improves performance.

Anytime you know how much space you are going to need you should reserve 
it up front.

So things look good for now.

Thanks,
   -Steve


More information about the pgrouting-dev mailing list