Reputation: 42245
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?
Upvotes: 5
Views: 5197
Reputation: 218710
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.
Upvotes: 5
Reputation: 171263
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)
Upvotes: 2