Bitcoin full node and query server

Jul 2, 2024

View in context in the libbitcoin Slack #general mirror.

evoskuil20:06
The downside to using custom allocators other than globally is that objects are not polymorphic. A std::vector<T> is not the same type as a std::vector<T, A> where A is a custom allocator. This is why std::pmr::polymorphic_allocator was introduced in C++17. While pmr types instantiated with a memory resource are polymorphic, they require a constructor parameter, and aren't polymorphic with std::vector<T>:
template <typename T>
using pmr_vector = std::vector<T, std::pmr::polymorphic_allocator<T>>;

class my_memory_resource : public std::pmr::memory_resource
{
    ....
}

void foo()
{
    my_memory_resource mem_res;
    auto my_vector = pmr_vector<int>(0, &mem_res);
    std::vector<int> v;
    my_vector = v;
}
(edited)
✅ 1