I still want there to be a single instance. You need to have the interface take TransactionRef by rvalue ref to make that work (TransactionRef &&) as Adam mentioned. This forces the caller to either pass an rvalue or use std::move() -- which forces it to be explicit. The point of unique_ptr is to enforces single ownership (any current violation of which would be a serious bug) with minimal overhead. I suspect that the performance issue you saw initially was that the compiler simply wasn't in-lining the construction? shared_ptr is of course more expensive due to the need to maintain a thread safe ref count. Any user which actually needs the ref count would probably be just as slow with a hand-rolled implementation (assuming we use make_shared). Any user which doesn't actually need the ref count could be switched to use unique_ptr. -Sam
On Thu, Dec 3, 2015 at 9:40 AM, Somnath Roy <somnath....@sandisk.com> wrote: > Hmm..Thanks Adam, so, one of the cleanups on the Ceph path could be to > introduce make_shared.. > We will come up with a prototype of optimized io path with removing > unnecessary use of shared_ptr and see how much overall gain we are getting.. > > Thanks & Regards > Somnath > > -----Original Message----- > From: Adam C. Emerson [mailto:aemer...@redhat.com] > Sent: Thursday, December 03, 2015 9:17 AM > To: Somnath Roy > Cc: Casey Bodley; Sage Weil; Samuel Just (sam.j...@inktank.com); > ceph-devel@vger.kernel.org > Subject: Re: queue_transaction interface + unique_ptr + performance > > On 03/12/2015, Somnath Roy wrote: >> I don't think make_shared / make_unique is part of c++11 (and ceph is using >> that). It is part of c++14 I guess.. > > std::make_shared is in C++11, std::make_unique is in C++14. In addition to > performance, std::make_shared is also more correct, in that: > > std::shared_ptr<T>(new T) > > can leak object allocated by 'new T' if the allocation for the shared_ptr > fails. > > std::make_unique is nice for cleanliness and symmetry, but doesn't add > anything for performance or safety. (Also you can write your own make_unique, > where make_shared is intimately involved with the details of shared_ptr.) -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html