As far as I can tell, the main difference between these two classes is that your type INHERITS FROM ReferenceCountedObject
whereas shared_ptr
OWNS your type. What this actually means is that with ReferenceCountedObject, your type gains a member variable that tracks the use count and a few member functions for modifying that use count.
Are there any plans to deprecate ReferenceCountedObject usage from the framework and switch to std::shared_ptr, the same way that std::unique_ptr
has replaced ScopedPointer
.
I’ve always found the whole ReferenceCountedObject<>
and
using Ptr = ReferenceCountedObjectPtr<Foo>
semantics really confusing, compared to just having a std::shared_ptr member variable in your class that’s using Foo.
here’s an example where a std::shared_ptr would be a much nicer return type:
template <typename NumericType>
typename IIR::Coefficients<NumericType>::Ptr IIR::Coefficients<NumericType>::makeLowPass (double sampleRate,
NumericType frequency,
NumericType Q)
{
jassert (sampleRate > 0.0);
jassert (frequency > 0 && frequency <= static_cast<float> (sampleRate * 0.5));
jassert (Q > 0.0);
auto n = 1 / std::tan (MathConstants<NumericType>::pi * frequency / static_cast<NumericType> (sampleRate));
auto nSquared = n * n;
auto invQ = 1 / Q;
auto c1 = 1 / (1 + invQ * n + nSquared);
return *new Coefficients (c1, c1 * 2, c1,
1, c1 * 2 * (1 - nSquared),
c1 * (1 - invQ * n + nSquared));
}
that return *new Coefficients(...);
just screams I'm a leak
to the untrained eye, even though that return type of ::Ptr
is actually ReferenceCountedObjectPtr<Coefficients>;
…
Perhaps ReferenceCountedObject
and ReferenceCountedObjectPtr
are relics from the pre-C++11 days of JUCE 3…
A lot of the new additions and updates to the library are very easy to read, use, and understand because they make use of modern C++. IMHO, ReferenceCountedObject
and ReferenceCountedObjectPtr
are 2 of the harder-to-use, read, and understand classes of the framework that could use some updating or replacing