Frage

I tried to add to my project rather limited functionality from the Boost library, namely allocating memory for small objects from a pool with the help of the 'pool_allocator' class, and discovered that I need to add to the project dependendencies to 4 debug static library files and to 4 release static library files. I.e. 8 library file dependencies are needed for a single line like this:

boost::container::vector<int, boost::pool_allocator<int> > v;

Is there a way to using these classes without linking to the static libraries? (Maybe a certain combination of the template parameters?)

War es hilfreich?

Lösung

All I read about boost pool is: don't use it at all. The library is rather old (in boost 1.54 all files have copyright 2000 and 2001 except pool_alloc.hpp, which was edited in 2010) You can look here for an question about performance (look for the answer of James Kanze). If you want only to use boost, I would suggest to use another library. If you need a custom allocator, do benchmarks.

Edit:

From Pools docu:

In general, use Pools when you need a more efficient way to do unusual memory control.

So the qustion is what exactly is unusual memory control? Does it meet your special need to memory? Andrei Alexandrescu has written in "Modern C++ Design" about memory allocation and that there may be very different requirements depending on allocation and deallocation patterns. But according to this paper he isn't convinced it was a very good chapter.

So for me the final question is wether pool is better than std::allocator for the problems memory management? You have to messure it. Even with litle logic implemented in pool there might be more efficient algorithms for memory management used in your implementation. By the way one of the bugs of pool is "Boost pool library it not header only as claimed in documentation".

Andere Tipps

Identify the files requried from boost, and add them to your project individually, or add a .cpp to your project that #include's the requried .cpp's. (Not really recommended)

or

generate your project files by a script, so that adding such dependencies is easy. Setting this up is a pain, but having it is great

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top