I am trying to create a custom cashing mechanism where I am returning a weak_ptr
to the cache created. Internally, I hold a shared_ptr
to control the lifetime of the object.
When the maximum cache pre-set is consumed, the disposer looks for those cache objects that are not accessed for a long time and will clean them up.
Unfortunately this may not be ideal. If it was possible to check how many cache objects can be accessed through the weak_ptr
, then this can be a criteria for making the decision to clean up or not.
Turns out there is no way to check how many weak_ptr(s)
have handle to the resource.
But when I look at the shared_ptr
documentation and implementation notes
=> the number of weak_ptrs
that refer to the managed object
is part of the implementation. Why is this not exposed through an API ?
Aucun commentaire:
Enregistrer un commentaire