|
Boost : |
From: Cédric Venet (cedric.venet_at_[hidden])
Date: 2007-08-11 11:00:23
> > Do you have any evidence of this? I've read somewhere that Visual 8
> > does something like this, but I hope this is not the COMDAT folding
> option.
> > This redundant machine code erasing is performed by the linker, the
> > code is still instantiated at compile time, so we are not going to
> > save much compilation time.
>
> No, it's not some new esoteric thing: Given some code like
>
> template<typename T> struct X
> { /* code inside that only uses T* */ }
>
> the compiler can determine that an incomplete type suffices for 'T' and
> that instances for any 'T' are interchangeable.
>
I tried with std::vector<type*> (cf joined source file) and it is the COMDAT
folding which do the work:
Without: 36ko
With: 28ko
(the others options by default, in particular Win98 optimization is on
bumping the size)
The COMDAT folding is on by default.
I don't know how much this affect the compile time, but at least it should
greatly reduce the code bloat.
It could break some code:
template< class T >
void testFct(T t) {
std::cout << t << std::endl;
}
...
std::cout << "ptr1: " << static_cast< void(*)(t1*)
>(&testFct<t1*>) << std::endl;
std::cout << "ptr2: " << static_cast< void(*)(t2*)
>(&testFct<t2*>) << std::endl;
with COMDAT folding the function address are the same (not without)
(using VS8)
Regards,
-- Cédric Venet
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk