First, describe the configuration of a PC as follows: Operating System: Mac OS lion 10.7.3 (64 bit) CPU: Intel I5 memory: Samsung ddr3 1333 4G Compiler: xcode 4.3.2 (64 bit) the Code is as follows:
#include<iostream>//author:1025679612@qq.com//csdn:wind_2008_06_29#include<typeinfo>usingnamespacestd;template< typename FirstType,typename SecondType, typename ThirdType,typename FourthType >struct Doublify{ //empty !};template<int N>struct Trouble { typedefDoublify< typenameTrouble<N-1>::LongType, typenameTrouble<N-1>::LongType, typenameTrouble<N-1>::LongType, typenameTrouble<N-1>::LongType > LongType;};template<>struct Trouble<0>{ typedefdouble LongType;};int main(){ Trouble<900>::LongType value; cout<<typeid(value).name()<<endl;}
The compilation progress of the compiler was shown above when I came back from the stool. (this is also where I clicked the compilation, and it is also there when I came back ). haha, my compiler was finally speechless.
Explanation: some people may think that the reason why the compiler compilation is so slow is the constant instantiation of trouble. Actually, it is not. Trouble can be instantiated for a maximum of 900 times. But why is the compiler slow, the reason is that the compiler uses all the time to write the name of the template after instantiation. Those names are hundreds of millions of characters, you can see in my code that there are only a few characters, but the name of the compiler will be changed ). the time for the compiler to read and write hundreds of millions of characters can be imagined. I changed the instantiation constant to 10, and the compiler compiled for 5 s, and we can see that the name given to the value by the compiler is: the compiler hopes that this name will not scare you. Let's think about it again, when the number is 900, what is the Compilation Time? It must have been the day I saw Marx (note that the time here is the exponential growth relationship). What about the symbol length? It may be several hundred million characters, haha. if you want to test vs, I suggest you change 900 to 20. 900 is too large, VS is 32-bit, and the memory space is not enough, during compilation, an error will definitely occur. You can try it by yourself when you change it to 20.
If you want to reprint it, please indicate the source. Thank you.