What's the pmr namespace?

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?
pmr stands for polymorphic.
What means this, what's the difference between standard topics?
Obviously you've googled it.
What specifically don't you understand?
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.
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
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.
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.