|
Boost : |
Subject: [boost] [type_erasure] Inefficient extra shared_ptr copy when passing parameter of type _self
From: Yuanchen Zhu (yuanchen.zhu_at_[hidden])
Date: 2017-02-01 16:54:15
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk