Summary
In this follow-up to previous PMR episodes, Jason addresses mistakes in his earlier allocator discussions. He clarifies terminology (memory resource vs. allocator) and demonstrates two significant PMR gotchas using a custom print_allocator that logs allocations. The episode reveals how initializer lists and vector::push_back() can cause unexpected allocations when used with PMR containers because initializer list elements are created with the default memory resource, not your custom one. Jason shows how to correctly build PMR-aware containers using a custom helper template function that reserves space and uses in-place construction.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[mem.res]68% match -
[diff.cpp03.containers]59% match -
[mem.poly.allocator.class]54% match -
[allocator.adaptor.members]52% match -
[mem.res.monotonic.buffer.general]52% match -
[mem.res.pool]52% match -
[allocator.adaptor]51% match -
[mem.poly.allocator.class.general]49% match -
[scoped.adaptor.operators]49% match -
[default.allocator]48% match - + 6 more related sections