Generic questions on inline functions and linking
Tim Shen
timshen@google.com
Thu Jul 23 04:36:00 GMT 2015
Thanks for the detailed explanation of ODR. :)
On Wed, Jul 22, 2015 at 2:45 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> really good to keep them inlined since they are anyway in the header,
>> and there is no real reason should we let use to keep multiple copies
>> in an executable.
>
>
> I don't think I understand this last sentence, because you won't get
> multiple copies kept in the executable anyway, the linker will only
> keep one copy of each symbol in the final executable.
Sorry, I misunderstood template functions a bit; it turns out I also
observed a different thing, that's not necessarily related to the
above one.
My observation is: adding inline specifier to a *template* member
function definition outside of its class scope improves the
performance and reduces the binary size.
Taking trunk as an exmaple. I added inline for each function in
include/bits/regex_executor.tcc, and recompiled a file that is similar
to our check-performance test file, then I observed a reduced binary
size (with 3 less exported symbols) and slight performance
improvement.
I tried to read the standard for whether a template member function
definition is implicitly inline, but failed :P. If it's true, then why
do we have different generated code here? If it's false, what's the
difference?
Thanks :)
--
Regards,
Tim Shen
More information about the Libstdc++
mailing list