Quantcast

[type_erasure] Inefficient extra shared_ptr copy when passing parameter of type _self

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[type_erasure] Inefficient extra shared_ptr copy when passing parameter of type _self

Yuanchen Zhu
Hi List,

I have been using boost::type_erasure a bit. I found that in the case of
implementing equality_comparable, when it passes into operator== a
placeholder argument corresponding to some any<C, T>, it always wraps it in
a param<C, T>, which internally instantiates an any<C, T&>. While this
instantiation does not cause the actual content to be copied, it always
clone the share_ptr pointing to the dispatch table, causing an extra
shared_ptr construct/destruct invocation whenever I do an equality
comparison.

This source of inefficiency seems unnecessary to me. Is it possible to
modify param<C, T> such that it only stores non-ref counted raw reference
to the original argument? Of course the functions in
type_erasure::detail::access need to be updated accordingly.

Will this modification break some grander scheme underlying type_erasure
that I am unaware of, being new to the code base?
It seems to me that when param<C, T> wraps a temporary, the temporary is
guaranteed to live past the lifetime of the invocation.

Can people vet this idea before I take a stab at changing the code?

Thanks,
Yuanchen

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Loading...