Need to null check cached pointer from multiple sources, like so:
double pointer:
int *ptr = new int(10);
int **pptr = &ptr; // from another source
ptr = nullptr;
cout << *pptr << endl; //nullptr
shared_ptr:
shared_ptr<int> sptr = make_shared<int>(10);
weak_ptr<int> wptr = sptr; //from another source
sptr.reset();
cout << wptr.lock() << endl; //nullptr
Concerns:
I'm not especially fond of the double pointer syntax not to mention it can be unsafe, but I keep hearing that shared_ptr is really slow due to reference counting which I don't really need because only one source is supposed to be in charge of object scope. Is the loss of whatever performance worth it with managed memory?
Preferably, are there any alternatives to either of these?