In C ++, I use boost::shared_ptr and boost::weak_ptr to automatically delete objects that are no longer needed. I know this work with reference counting.
In Java, the memory is managed by the garbage collector, which considers embedded object references as strong, WeakReference weak and SoftReference as something intermediate (can be collected by GC, but can also survive in GC), which is very convenient for caching objects for some time, but discarding them as soon as free memory becomes low.
So now I am back in C ++, and I miss the fact that I have soft links. I wonder if soft handling with reference to an account is possible. When is the last strong link to the object cleared, and does the soft link remain when it is finally deleted? I could think of some schemes, but none of them seem clever to me.
Just in case, there is the correct semantics for soft links along with link counting, I wonder if this has already been implemented, perhaps in a way that is even compatible with boost::shared_ptr (or the C ++ TR1 equivalent of std::shared_ptr , if that gone).
If there is no answer to both questions, what are the alternatives to the object caching script?
EDIT: Of course, I'm talking about a situation where caching is really useful, because objects are expensive to create (think of a few database accesses and network requests), but there are too many of them to keep them forever.
c ++ memory-management boost shared-ptr soft-references
Lena Schimmel Jul 04 '10 at 14:45 2010-07-04 14:45
source share