Alisdair Meredith: Allocators in C++11
Channel: CppNow
Date: 2013-06-25

← View entire schedule
Allocators in C++11
Flug, Thursday 12:55pm  - 2.10pm
Alisdair Meredith     
This session will provide some motivation for why you would want to create a custom allocator in the first place, walk through some of the fun coding idioms required of the standard library vendor, show how simple a new allocator is to write, and finally show how this changes the way we should implement containers using the new model.

Allocators have been a part of the C++ standard since the initial STL, and have generally been ignored for most of that time, as a feature that was not quite fit for purpose. Various efforts have been made over the years to provide useful allocators other than std::allocator, and generally not been successful, for a variety of reasons -- but the key problem is that the standard had an infamous 'weasel words' clause that essentially allowed the container to ignore the allocator supplied by the user if it chose to.

Bloomberg have extensive experience with a very different allocator model, where the allocator is not a part of the container type itself, and the type is given at run time, on a per-object basis. The challenge from the standards committee was to adapt the existing C++ allocator framework so that the Bloomberg model could be easily integrated without disrupting existing code. More, to make writing allocators themselves a simple exercise, so that anyone could easily provide their own allocators, with their own model, and expect them to work seamlessly with any conforming container.

The end results is the 'allocator_traits' of C++11, which have some entertaining implementation challenges for the library vendors, change the way containers access and use their allocators in general, but do indeed make writing new allocators much simpler.
---

*--*

---