Topic: get count of std::weak_ptr objects tracking a shared resource
Author: write2ramkumar@gmail.com
Date: Thu, 25 Dec 2014 00:16:32 -0800 (PST)
Raw View
------=_Part_3120_1097065242.1419495392857
Content-Type: multipart/alternative;
boundary="----=_Part_3121_80929152.1419495392857"
------=_Part_3121_80929152.1419495392857
Content-Type: text/plain; charset=UTF-8
It is useful to get the count of std::weak_ptr that are tracking a
resource just as we have a reference count of std::shared_ptr that tracks a
resource.
Most implementations already have this information but there is no API in
the standards to extract this information.
I can explain why I need this information in one of the scenarios that I
have in my project.
I have built a custom caching mechanism that does caching based on user
request. The cached objects are disposed when the memory consumed by
caching exceeds a pre-defined memory size set by the user. The cached
objects are returned to the user through std::weak_ptr. The utility of
the weak_ptr is primarily to avoid dangling pointers once the cache is
cleared. However, the logic of which cache object has to be disposed is not
a trivial decision and having a reference count of the number of weak_ptr
is of immense value.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_3121_80929152.1419495392857
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">It is useful to get the count of std::w<span style=3D"colo=
r: rgb(0, 0, 0); background-color: rgb(250, 250, 250);">eak_ptr </span=
>that are tracking a resource just as we have a reference count of std=
::<span style=3D"color: rgb(0, 0, 0); background-color: rgb(250, 250, 250);=
">shared_ptr </span>that tracks a resource.<div><br></div><div>Most im=
plementations already have this information but there is no API in the stan=
dards to extract this information.</div><div><br></div><div>I can explain w=
hy I need this information in one of the scenarios that I have in my projec=
t.</div><div><br></div><div>I have built a custom caching mechanism that do=
es caching based on user request. The cached objects are disposed when the =
memory consumed by caching exceeds a pre-defined memory size set by the use=
r. The cached objects are returned to the user through <span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0); background-color: =
rgb(250, 250, 250);">std</span><span class=3D"styled-by-prettify" style=3D"=
color: rgb(102, 102, 0); background-color: rgb(250, 250, 250);">::</span><s=
pan class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0); background-c=
olor: rgb(250, 250, 250);">weak_ptr. </span>The utility of the weak_pt=
r is primarily to avoid dangling pointers once the cache is cleared. Howeve=
r, the logic of which cache object has to be disposed is not a trivial deci=
sion and having a reference count of the number of weak_ptr is of immense v=
alue.</div><div><br></div><div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_3121_80929152.1419495392857--
------=_Part_3120_1097065242.1419495392857--
.