Reputation: 1979
I am trying to investigate the cause of the difference in performance between the two allocators, as shown in https://en.cppreference.com/w/cpp/memory/monotonic_buffer_resource. What I have found so far:
monotonic_buffer_resource
but not the std allocator, according to compiler explorer.libstdc++
, but could not find how
monotonic_buffer_resource
was selected to be used by the default pmr allocator.std::pmr::new_delete_resource()
should be used, and that should make default std allocator and default pmr allocator the same, but obviously it is not.void default_pmr_alloc() {
std::pmr::list<int> list; // uses monotonic_buffer_resource
for (int i{}; i != total_nodes; ++i) {
list.push_back(i);
}
}
void default_std_alloc() {
std::list<int> list; // uses operator new/delete
for (int i{}; i != total_nodes; ++i) {
list.push_back(i);
}
}
Upvotes: 0
Views: 411
Reputation: 10591
It does indeed use new_delete_resource
. (which from std::pmr::get_default_resource()
)
you can check it by
list.get_allocator().resource()->is_equal(*std::pmr::new_delete_resource()); // true
https://godbolt.org/z/qGTG57MfY
Not sure about what the benchmark is, but type erasure comes with it's own penalty, pmr
one would probably be slower.
Upvotes: 2