Loading…
CppCon 2018 has ended
Back To Schedule
Monday, September 24 • 15:15 - 16:15
An Allocator is a Handle to a Heap

Sign up or log in to save this to your schedule, view media, leave feedback and see who's attending!

C++17 introduced the std::pmr framework. In this framework, a std::pmr::polymorphic_allocator<T> holds a pointer to a std::pmr::memory_resource. The memory resource is in charge of managing and organizing the heap itself, and the allocator object is just a thin "handle" pointing to the memory resource.

This is not just a convenient implementation strategy for std::pmr! Rather, this elucidates the true meaning of the Allocator concept which has existed, unchanged, since C++98. An Allocator *is* a (value-semantic) handle to an (object-semantic) MemoryResource. Even std::allocator can — and should — be viewed as a handle to a global singleton "heap", and not as a heap itself.

From this core insight we derive many corollaries, such as the need for allocator types to be lightweight and efficiently copyable, the fundamental impossibility of implementing an "in-place" std::vector via stupid allocator tricks, and the philosophical underpinnings of "rebinding."

Time permitting, we'll
- discuss what we can expect from a "moved-from" allocator object
- relate the notion of "handle" to neighboring notions such as "façade" and "adaptor"
- suggest similarities between "allocator/heap" and "executor/execution-context"

Speakers
avatar for Arthur O'Dwyer

Arthur O'Dwyer

C++ Trainer
Arthur O'Dwyer is the author of "Mastering the C++17 STL" (Packt 2017) and of professional training courses such as "Intro to C++," "Classic STL: Algorithms, Containers, Iterators," and "The STL From Scratch." (Ask me about training your new hires!) Arthur is occasionally active on... Read More →


Monday September 24, 2018 15:15 - 16:15 PDT
Telluride (407)