ggg
ggg

Reputation: 1979

Cause of difference in performances of default pmr allocator and default std allocator

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:

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

Answers (1)

apple apple
apple apple

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

Related Questions