boost::pool_allocator needs eight static libraries?

余生颓废 提交于 2019-12-13 04:13:45

问题


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?)


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/17670094/boostpool-allocator-needs-eight-static-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!