Are there techniques to greatly improve C++ building time for 3D applications?

后端 未结 4 992
误落风尘
误落风尘 2021-02-01 18:30

There are many slim laptops who are just cheap and great to use. Programming has the advantage of being done in any place where there is silence and comfort, since concentrating

4条回答
  •  梦毁少年i
    2021-02-01 19:13

    Another point that's not mentioned in the other answers: Templates. Templates can be a nice tool, but they have fundamental drawbacks:

    • The template, and all the templates it depends upon, must be included. Forward declarations don't work.

    • Template code is frequently compiled several times. In how many .cpp files do you use an std::vector<>? That is how many times your compiler will need to compile it!

      (I'm not advocating against the use of std::vector<>, on the contrary you should use it frequently; it's simply an example of a really frequently used template here.)

    • When you change the implementation of a template, you must recompile everything that uses that template.

    With template heavy code, you often have relatively few compilation units, but each of them is huge. Of course, you can go all-template and have only a single .cpp file that pulls in everything. This would avoid multiple compiling of template code, however it renders make useless: any compilation will take as long as a compilation after a clean.

    I would recommend going the opposite direction: Avoid template-heavy or template-only libraries, and avoid creating complex templates. The more interdependent your templates become, the more repeated compilation is done, and the more .cpp files need to be rebuilt when you change a template. Ideally any template you have should not make use of any other template (unless that other template is std::vector<>, of course...).

提交回复
热议问题