简体   繁体   中英

Is there an elegant C++ implementation of fixed-size allocator?

I think a C++ library is "elegant" if the number of header files which must be included are as less as possible.

I know there have been existing fixed-size allocators like Loki::SmallObjectAllocator and boost::pool . Although both are excellent, I think they are not elegant and not easy to be seamlessly integrated into projects.

Most times, I only need a little part of boost library, but I have to install the whole library on my machine. For example, if I want to use boost::pool, I hope to just include ONE header file boost_pool.h and the work is done. Because I think a fixed-size allocator should not be so dependent on too many other components. In my opinion, ideal code should look like the following:

#include <boost_pool.h>

int main()
{
   boost::pool<int> p;
   int* v = p.allocate();
}

Does there exist such a library?

You are welcome to mine . Whether it is elegant or not, you can decide. But it is just one short header dependent upon just a couple of small standard headers. The allocator meets the C++11 allocator requirements, which are a subset of the C++03 allocator requirements. You can always add the C++03 boiler plate if you need it.

Are you using GCC? It's standard library comes with a few fixed-size allocators as extensions, see http://gcc.gnu.org/onlinedocs/libstdc++/manual/memory.html#allocator.ext

They're fairly standalone (not sure about elegant, it's a long time since I looked at their code properly)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM