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:
- In GCC, it seems that the default pmr allocator uses
monotonic_buffer_resource
but not the std allocator, according to compiler explorer. - I looked into the source code of the header files and
libstdc++
, but could not find howmonotonic_buffer_resource
was selected to be used by the default pmr allocator. - From my reading of the source code, it seems that
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);
}
}