Question

I am working on improving the performance of a program which uses both the Boost Graph Library and boost::bimap. Profiling revealed that most of the time was being spent in memory allocation and deallocation. Making the adjacency_list class of the graph library use boost::fast_pool_allocator improved performance significantly. A large chunk of the remaining memory allocations occur in boost::bimap, so I wanted to experiment with using a custom allocator there as well. The documentation says you can specify the allocator as the last template parameter of the bimap, but it does not say what type the template argument to the allocator itself should be. For example, for types X and Y, in

boost::bimap<set_of<X>, set_of<Y>, boost::fast_pool_allocator<Z> >

what should be filled in for Z?

Was it helpful?

Solution

I believe the answer is that for Z, you should fill in std::pair<X,Y>. This worked in my case, but I wanted to post here because

  • it's not obvious from the documentation
  • Boost code is not quick to read
  • Googling was unhelpful
  • and other people might have useful comments (for instance, I haven't tested if this depends on what the left or right view of the bimap is)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top