This is the opposite to regular allocators which make two containers using a different allocator also a different type.Īll the types for polymorphic allocators live in a separate namespace std::pmr (PMR stands for Polymorphic Memory Resource), in the header. You can change the memory resource at runtime while keeping the type of the allocator. Polymorphic Allocator contains a pointer to a memory resource class, and that’s why it can use a virtual method dispatch. Still, at its core, it uses a memory resource object to perform memory management. In short, a polymorphic allocator conforms to the rules of an allocator from the Standard Library. Let’s see how we can use it and hack to see the growth of std::vector containers. It’s much easier to use than a regular allocator and allows containers to have the same type while having a different allocator, or even a possibility to change allocators at runtime. The concept of a polymorphic allocator from C++17 is an enhancement to standard allocators from the Standard Library.
0 Comments
Leave a Reply. |