J
Jens Theisen
In general, you need ref-counting only when you _return_ 'ownership'
form a function (which is bad style anyway).
You don't return ownership. shared_ptr owns it's object and you return
a shared_ptr. If you return a shared_ptr from a function, that doesn't
mean that ownership is transferred - after all the function returning
it can still keep a copy.
In other cases
ref-counting is unnecessary. What would be the use of counting?
The question is: Why would you not? What's actually the problem?
As far as I can see, you are trying to make the following points:
1) new/delete asymmetry
2) some point about ownership that I don't fully understand
3) reference counting overhead which is sometimes unnecessary
4) spurious allocation that is sometimes unnecessary
5) additional indirection overhead
For 1, use the wrapper if you take it as that important.
For 2, can you elaborate what you mean?
For 3 - 5, the overhead is fairly small and generally considered worth
the safety. The spurious allocation is also worth the safety, but
could be alleviated by intrusive counting that you will probably also
disapprove of.
Did I miss a point?
One last question: How do you return expensive objects, a
vector, say, from a function?
Regards,
Jens