|
std::pmr::memory_resource* allocator = nullptr; |
Why?
The lifetime of the memory resource is not bound to the ref_info that made it, meaning that the memory resource can be destroyed early and cause lifetime issues. A solution around this is to force the memory resources to be managed by strong_ptr.
But how do you get a strong_ptr from an object that needs a strong_ptr for its control block. And the answer is static memory or global allocators. The static strong_ptr's do not need control blocks since they live for the duration of the program and thus can be the backbone of every other strong_ptr. This will ensure memory safety for our smart pointers.