5

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?

10
  • 3
    Have you looked at bcp? Not exactly the same, but it can easily be used as a starting point to shove everything into a single header. Commented Jan 22, 2013 at 9:53
  • 2
    "I hope to just include ONE header file boost_pool.h" - so, do the work once and put all related things in there? Seriously. Commented Jan 22, 2013 at 9:56
  • 2
    seems like you could install boost long time ago, but you needed just one thing and you decided it's not worth the effort. and the same every time you need something from boost. probably, it's time to install it finally? Commented Jan 22, 2013 at 9:59
  • 12
    Possibly the word you're looking for is "stand-alone" rather than "elegant". Boost sees "elegance" in a different way -- code is shared between different Boost components rather than being duplicated by every component that needs to do the same thing. The result, of course, is internal dependencies within Boost. Commented Jan 22, 2013 at 10:00
  • 1
    @AndyT: certainly some of the commonly-used stuff in Boost is defined differently in different platforms. I'm pretty sure that you can write a pool allocator (for that matter, a lot of Boost features) without a heavy platform isolation layer. But once you've got a fully-featured platform isolation layer you generally use it rather than re-implement the little bits of platform isolation that each component requires. Similarly for convenience tools like BOOST_FOREACH, once you have them you wouldn't avoid using them just in order to make your boost component more stand-alone. Commented Jan 22, 2013 at 10:37

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Note for Windows users: note that stateful allocators do not work yet in Debug mode under Visual C++ 2012 November CTP. There is some debug checking that uses Allocator::construct rather than std::allocator_traits<Allocator>::construct
2

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.