mercredi 29 juin 2016

Do timed pointers exist?

In some cases I desired to have some kind of timed-based smart pointer, for example to cache some bulky object but release it automatically after a certain time if not used. When the pointer is touched (dereferenced) the count down is restarted, and you can also halt the count down if you need to 'lock' the object alive for duration of a computation. Something like:

timed_ptr<Type,30> p = new Type(); \\object is deleted after 30 seconds, and pointer set to a checkable 'null' state

...

p.stop_count_down();
// do something with the object, guaranteed it won't expire while we still need it. 
p.start_count_down();

Does anything of this sort exists in boost or other library?

Aucun commentaire:

Enregistrer un commentaire