What's the pmr namespace?

Dec 22, 2019 at 3:47pm
Very often when I browse through the c++ reference, I register that some stuff is in the namespace pmr. I searched for an explanation of this but didn't found such. So what it means?
Dec 22, 2019 at 4:19pm
pmr stands for polymorphic.
Dec 22, 2019 at 4:32pm
What means this, what's the difference between standard topics?
Dec 22, 2019 at 4:40pm
Obviously you've googled it.
What specifically don't you understand?
Dec 22, 2019 at 4:50pm
Yes, I have googled it. But I got a lot of pages where polymorphism itself is explained, but not the need for a polymorphic namespace. So I ask me, for what stuff it's needed. I know about runtime polymorphism and i know compile-time polymorphism. But both could be gained with the standard library stuff.
Dec 22, 2019 at 5:07pm
Dec 22, 2019 at 5:26pm
The gist of it is this:
Lots of containers take an allocator type as part of their template argument. An allocator is an object that obtains and releases uninitialized memory. Sometimes, changing the allocator from the default std::allocator to another, smarter type can improve performance or functionality.

In allocator-aware code, one might need to deal with lots of types that differ only in their allocator argument. For instance, if one needs to deal with a
std::vector<int, allocator_alpha> and
std::vector<int, allocator_beta>,
This is a problem because we don't usually care about the allocator type: it's just in the way.

std::pmr::vector<int>
Is a way to express the type
std::vector<int, /* any allocator at all */>
With the help of runtime polymorphism.

Watch Pablo Halpern's lecture:
https://www.youtube.com/watch?v=v3dz-AKOVL8
Last edited on Dec 22, 2019 at 5:31pm
Dec 22, 2019 at 10:00pm
Thanks for advising to the video stream.
Till now I haven't bother about memory management and allocators, maybe because I never needed that so far.

So if I have it correctly understand, all containers at pmr namespace could use an object, derived from polymorphic_allocator class, and thus we obtain runtime-polymorphism.
Dec 23, 2019 at 1:42am
A polymorphic_allocator is just a facade that makes a pointer to a memory_resource look like an Allocator.

One typically derives from memory_resource, which actually does the job of sourcing the uninitialized bytes in a specialized way.
Topic archived. No new replies allowed.