C++ Weekly - Ep 222 - 3.5x Faster Standard Containers With PMR!
Why Stack Overflow recommends it
Stack Overflow users link it when explaining how pmr allocators can cut allocation overhead for containers like unordered_map, and as a short introduction to PMR.
Recommended by 4 people across 4 different months, 2020 to 2021.
What it is
A ten-minute episode of Jason Turner's C++ Weekly series showing how C++17 polymorphic memory resources (PMR) can make standard containers about 3.5 times faster. It walks through a benchmark of swapping in a PMR allocator and links to a related talk on allocators.
What people said
Recommends ravnsgaard · 2020-06 · Stack Overflow · on “how does std::pmr::memory_resource makes performance difference with std::container?”
They're completely orthogonal concepts. PMR is an allocator-system, not an RAII system. This is a fairly big subject; you may want to watch [this video] these [LINK] videos [LINK] . They give a nice overview of PMR and related technologies.
Recommends Surt · 2020-10 · Stack Overflow · on “unordered_map to find indices of an array”
std::unordered_map<int, int> is often implemented as if it was std::vector<std::list<std::par<int, int>>> Which causes a lot of allocations and deallocations of each node, each (de-)allocation is using a lock which causes contention. You can help it a bit by using emplace instead of insert, or you can jump out in the fantastic new world of pmr allocators. If your creation and destruction of the pmr::unordered_map is single threaded you should be able to get a lot of extra performance out of it. See Jason Turners C++ Weekly - Ep 222 - 3.5x Faster Standard Containers With PMR! [this video] , his example is a bit on the small side but you can get the general idea.
Recommends Oussama Ben Ghorbel · 2021-02 · Stack Overflow · on “Custom allocator for nested containers”
Creating a scoped allocator in C++11/C++14 was a little bit challenging. So I opted for a very modern solution introduced in C++17. Instead of implementing an allocator, I used polymorphic_allocator [LINK] . Polymorphic allocators are scoped allocators, standard containers will automatically pass the allocators to sub-objects. Basically, the idea was to use a polymorphic allocator and inject it with monotonic_buffer_resource [LINK] . The monotonic_buffer_resource can be initialized with a memory resource [LINK] . Writing a custom memory resource was very simple: class custom_resource : public std::pmr::memory_resource { public: explicit custom_resource(std::pmr::memory_resource *up = std::pm
Recommends Ben · 2021-10 · Stack Overflow · on “Storing heterogeneous data continuously in memory as a sequence of chars”
@user542101 That's right. This video shows how it's used: [this video] It's pretty advanced, and looking at your problem again, I don't know that it's the right approach.