Use pre-compiled headers to accelerate compilation speed - taking Borland C ++ Builder as an Example (5)

zhaozj2021-02-17  34

Use pre-compiled headers to accelerate compilation speed - taking Borland C Builder as an Example (5)

Author: Wang Sen Technology Management Institute moli.mt88g@nctu.edu.tw Taiwan Jiaotong University Prior to this, all of the tests are simple examples Applets. For the readers, although the conclusions above are very useful, if we want to develop a general GUI program? Let's take a look at a relatively practical example. We use File / New Application to re-build a GUI's Windows application. When we press Make, we find that the results should be compiled as follows:

Compile number 173358 Row compilation time 4.05 seconds VCL50.CSM size 7459 kbcache file number 2 (VCL50.CSM and VCL50. # 00)

If we put a lot of different components on the Form, we will find that the original file is always only #include , and only some related HPP files are introduced in the header file. So if we want to explore whether the program that can be compiled using the VCL header file is faster, the place we have to be a brain is VCL.h this file! So we open vcl.h, found that he only introduced VCL0. H, so we open vCl0.h again, 嘿嘿 ~~ Let us find interesting things.

In vcl0.h, we see several conditions compilation, as follows: // Database Related Headers / / # ified #include #include #include #endif // INC_VCLDB_HEADERS # if defined (INC_VCLEXT_HEADERS) #include #include #include #include #include < DBGRIDE.HPP> #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif // INC_ALLVCL_HEADERS # if defined (INC_OLE_HEADERS) #include #include #include #include #include #include #include #include #include #include < AxCtrls.hpp> #include #include #i NClude # ENDIF // Using Atlvcl.h // # if def_atl_headers #include #ENDIF See these conditional compilation, then think of the previous compilation we mentioned Mark, what is the smart reader thinks what do you think? Yes, if we change the original #include #pragma hdrstop in the original program file to #DEFINE INC_VCLDB_HEADERS # definer inc_ole_headers # define inc_Atl_Headers # Define Inc_ATL_HEADERS # Include #pragma HDRSTOP We use Build that you will get the following results 811680 row compile time 15.07 seconds VCL50.CSM size 22483 kbcache file number 2 (VCL50.csm and VCL50. # 00)

This experimental results also tell us:

If you use #define inc_vcldb_headers, # define inc_ole_headers, #define inc_ore_headers, you can ask the compiler to compile some preset non-pre-compiled headers, so almost all the use of VCL writing Windows programs. All headers will be pre-compiled. If it is not used, try not to use four define. For example, if we don't use the database component, don't use #define inc_vcldb_headers; if you don't use the ATL (Active Template Library), don't use #define inc_atl_headers, because so, only waste extra Time compilation, but also because of the pre-compiling of the header files, caching makes Cache becomes large, which is just a waste of hard disk space. All analytics and conclusions in front of the synthesis, the author provides a better solution, this solution is to correct all the #include instructions from the previous paragraph "to move all the #include instructions to a single header file. Then, each file inside Project is directly introduced into this single header file, we can change the contents of the INCLUDEALL.H of this header to includeall.h # ifdef use_vcldb # define inc_vcldb_headers # Endif # ifdef USE_VCLEXT # define INC_VCLEXT_HEADERS # endif # ifdef USE_OLE # define INC_OLE_HEADERS # endif # ifdef USE_ATL # define INC_ATL_HEADERS # endif # include #include #include #include <... to be introduced into other System header file ...> #ifdef use_userdef # include "unit1.h" #include "unit2.h" #include "unit3.h" #include "... user self-reserve header ..." #ENDIF In the future, we can introduce the user's self-reserve header speed at the beginning. Once the program development is reached, we will use the Directories / Conditionals page in Project / Option, in the Edit of Conditionals. Fill in Use_UserDef in Box to allow our self-reserve headers to enjoy the benefits of Pre-Compiled Headers technology. Similarly, we can fill in this definition of USE_VCLDB, USE_VCLEXT, USE_OLE, USE_ATL, or make all relevant headers inside the VCL take advantage of Pre-Compiled Headers technology. As shown below:

In fact, there is this dialog box. We can't write this complex, as long as you write into includeall.h # include #include #include #include <... The system header file to be introduced ...> #ifdef use_userdef # include "unit1.h" #include "unit2.h" #include "unit3.h" #include "... user-reserve header file ..." #ENDIF then Fill in the Directories / Conditionals subtitle fill in INC_VCLDB_HEADERS, INC_VCLEXT_HEADERS, INC_OLE_HEADERS, INC_ATL_HEADERS. In the end of the conclusion, we must remind the readers to write the test experience when writing this article: Please do not put the template header file before the compiler command #pragma hdrstop, otherwise the pre-compiled headers technology will Failure. Personally, this is a quite relationship with the instantiation. If there is a constant definition in the header (such as Const Int A = 3;), the pre-compiled headers technology will also be invalid, but there is no problem if it is a constant declaration (such as Const Int A;).

[Note 1: Activate the pre-compiled headers function of the compiler] Does the compiler use pre-compiled headers technology, can be determined by two places: 1. Project / Option Compiler Page by PROJECT / Option

As shown, the preset compiler action is Cache Pre-Compiled Headers, and can also specify the file name of Cache. Readers can press F1 to find more messages, usually we don't have to get the settings of this place. 2. Command Column Instruction When we do not use the IDE to compile Project, you can use the compiler parameter -H / -HU / -H to control the relevant behavior of Pre-Compiled Headers. [Note 2: BCB ON-LINE HELP Interpretation of #pragma HDRSTOP] Move the mouse to the HDRStop of #pragma hdrstop and press F1, you can see the instructions for this compiler instruction.

转载请注明原文地址:https://www.9cbs.com/read-30320.html

New Post(0)