2

In last year's CppCon, the wonderful Andrei Alexandrescu gave a talk on designing memory allocators, (in?)aptly named:

std::allocator is to Allocation what std::vector is to Vexation

(earlier titles: "std::allocator is to Allocation what allegator is to allegation" or "writing allocators which don't not-work").

Now, I'm not looking for a copy of his code, but rather something based on it, which:

  • Has proper/better support for alignment (hopefully via template parameters, perhaps even including the alignment in the Blk structure?).
  • Incorporates a richer variety of known allocation algorithms
  • Is used by more than 2 people :-)

Is there such a thing out there?

0

Yes, there is: Felix Petriconi's

Allocator Builder library (GitHub)

Quoting from the repository description:

A highly composable, policy based C++ allocator.

The layout idea of the library is was presented by Andrei Alexandrescu at the C++ and Beyond 2013 seminar and at the CppCon 2015.

So just what OP asked for. Additional general information:

The composable allocators provided as of March 2017 are:

  • affix_allocator: Allows to automatically pre- and sufix allocated regions.
  • allocator_with_stats: An allocator that collects a configured number of statistic information, like number of allocated bytes, number of successful expansions and high tide
  • bucketizer: Manages a bunch of Allocators with increasing bucket size
  • fallback_allocator: Either the default Allocator can handle a request, otherwise it is passed to a fall-back Allocator
  • (aligned_)mallocator: Provides and interface to systems ::malloc(), the aligned variant allocates according to a given alignment null_allocator An Null allocator
  • segregator: Separates allocation requests depending on a threshold to Allocator A or B
  • (shared_)freelist: Manages a list of freed memory blocks in a list for faster re-usage. (The Shared variant is thread safe)
  • (shared_)cascading_allocator: Manages in a thread safe way Allocators and automatically creates a new one when the previous are out of memory. (The Shared variant is thread safe, but it needs further improvements, because it does not frees unused allocators)
  • (shared_)heap: A heap block based heap. (The Shared variant is thread safe manner with minimal overhead and as far as possible in a lock-free way.)
  • stack_allocator: Provides a memory access, taken from the stack

So it's a solid base to start off of. Lots of GitHub 'stars' and followers, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.