abseil / abseil-cpp

Abseil Common Libraries (C++)
https://abseil.io
Apache License 2.0
14.94k stars 2.61k forks source link

API request: an equivalent of boost::intrusive_ptr supported in absl #344

Open jmarantz opened 5 years ago

jmarantz commented 5 years ago

I have a data structure with a high cardinality. and I want to be able to keep it weakly in a set, returning ref-counted pointers to it to callers. When all the callers drop their refs, I need to remove it from the set. I can easily accomplish this with std::shared_ptr and std::weak_ptr, or using std::enable_shared_from_this. However those options consume excess memory.

https://www.boost.org/doc/libs/1_70_0/libs/smart_ptr/doc/html/smart_ptr.html#intrusive_ptr is a better solution, but comes with the baggage of, well, boost :) Also see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0406r1.html

See also a proposed use-case (and a home-grown workaround) in an Envoy Proxy PR: https://github.com/envoyproxy/envoy/pull/7364/files/2de13dd52a0428838a8b3ab2656035956805791e It would be better not to maintain this shared_ptr replacement in Envoy long-term. This feels in-line with absl's pattern of providing generally useful functionality.

derekmauro commented 5 years ago

I will sum up my response to the internal request here.

We think this is a reasonable request, and internally we have a couple candidate APIs that implement intrusive reference counting. However, we think we need to do some design work and a full API review to come up with an API that we are happy releasing, since we don't think any of the candidates we have are ideal. Then we need to do the cleanup for whatever changes we decide to make to the API we would release. All of this will take a lot of time.