Your cache class should own a shared_ptr, and it should hand out weak_ptrs.
shared_ptr implies ownership and access, weak_ptr implies access but not ownership. unique_ptr imples unique ownership and unique access.
You said, "and the data is really supposed to be shared around to avoid duplicates.", just incase you don't know, shared_ptr only shares the same variable when you tell it to.
If you do:
boost::shared_ptr<MyClass> ptrA = boost::make_shared<MyClass>(...); boost::shared_ptr<MyClass> ptrB = boost::make_shared<MyClass>(...); boost::shared_ptr<MyClass> ptrC = ptrA;
ptrA and ptrC point to the same MyClass. ptrB is an entirely different variable that points to a different MyClass.
You probably already know that, but I figured I'd mention it just incase.
You might also want to look into flyweight.
I also might be misunderstanding what you mean. Could you give an example of your problem? 'heap' memory means dynamic memory, IIRC. Shared pointers only operate on heap memory. Did you mean you have variables on the stack that you want to give shared access to? If so, use raw pointers (normal C or C++ pointers). Raw pointers aren't evil, they're just another tool in your toolbox. Not every use of pointers are supposed to be replaced by smart pointers.