Author: taowen (taowen.bitapf.org)
http://www.cnblogs.com/taoen/archive/2004/08/04/30132.aspx
Kol, I don't know how many friends know this thing. It is an alternative to a VCL. If you don't even know the VCL, it doesn't matter, VCL is a standard library of Delphi, providing a full functionality. The author of Kol believes that the procedure written by VCL is too large, so he wrote Kol and successfully gave the prior art solution. The homepage of KOL is: http://bonanzas.rinet.ru/kol, in fact, not the library I like. May be because there are too many strange techniques inside. 12K GUI programs can't touch me at all, at least I have used Win32ASM, used WTL. But I care about how Kol makes the code size, how the "junk" code is eliminated. About this issue I found some answers in an article that is praised Kol: http://bonanzas.rinet.ru/art002.htm. In fact, how to expand in the code, since I met the compilation, I have been thinking about it after I met the essence of OOP. Let's take a look at how the article is so huge. The author believes that VCL has two main reasons: 1, useless virtual functions cannot be removed by Smart Linking technology. 2, premature construction members. This is my intention to the author's point of view, explain it a little one. Smart linking is Delphi optimization technology that can be removed from the final code from the unused class and the non-virtual function. This is a link technology, so it doesn't have a way to interfere with the V-table, so it is impossible for virtual functions. So normal member functions and global functions are not used, they will not enter the final code. Once the virtual function, once the class is referenced, it must also include entering, worse, the other classes referenced in the virtual function, also contains it together, and the virtual functions of those classes should continue this process. I really didn't expect it to avoid code expansion. Under normal circumstances, Lazy Load is used to speed up the creativity of the object. The code expansion brought by the classes used at this time is inevitably, because other compilers cannot do such smart linking, the other is the destructive function that must be referenced to the destructor of the member variable. However, in Delphi, you can avoid direct calls of the destructor through the virtual function free of TOBJECT. And Delphi has Smart Linking Technology. This if there is a member font: tfont. As long as all references are made through GetFont, Font is created for the first time to call GetFont. This does not call GetFont, and TFONT's code will not be included. It can be seen that the optimization technology of the compiler and linker is a cutlery that reduces code size. Delphi or SMART Linking of Pascal makes Kol's strange kneades. I have only heard of Function Level Linking, no Delphi thorough. The article also mentioned that the useless virtual function is possible. Perhaps this optimization is indeed possible through global analysis. But I think about it, it is no longer a static world. The reflection of dynamic languages may not be necessarily obstacles to this optimization technology. Let's criticize the criticism of Kol. To avoid using virtual functions, it gives up strong types. Gring all the controls with a TControl all. I think the Rubbish code brought by the code expansion, the CPU time, the network bandwidth is cost, but this is greater than the return price of OOP. It can be said that it is not worthless. Eventually my point of view: 1. The code expansion should be avoided, although it is not necessarily used to remove unusable code, or the shared library or mesh calculation. Because useless code occupies memory, CPU time and network bandwidth. 2. The solution of code expansion should analyze its root sources. Function Level Linking can solve the problem.