Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 676
xmllmx Avatar asked Jan 22 '13 09:01

xmllmx


1 Answers

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.

like image 200
Howard Hinnant Avatar answered Nov 15 '22 09:11

Howard Hinnant