Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do YOU reduce compile time, and linking time for Visual C++ projects (native C++)?

How do YOU reduce compile time, and linking time for VC++ projects (native C++)?

Please specify if each suggestion applies to debug, release, or both.

like image 947
Brian R. Bondy Avatar asked Dec 12 '08 21:12

Brian R. Bondy


People also ask

Why does C take so long to compile?

Header files This is probably the main reason, as it requires huge amounts of code to be compiled for every compilation unit, and additionally, every header has to be compiled multiple times (once for every compilation unit that includes it).

Why is compile time faster?

Also the compiler will internally used optimized code. And it will convert the nonesense recursive approach to an iterative approach. And to calculate that values will take less time than the compiler overhead functions. So, that is the real reason.

What occurs at compile time link time and run time?

Compile-time and Runtime are the two programming terms used in the software development. Compile-time is the time at which the source code is converted into an executable code while the run time is the time at which the executable code is started running.


2 Answers

It may sound obvious to you, but we try to use forward declarations as much as possible, even if it requires to write out long namespace names the type(s) is/are in:

// Forward declaration stuff namespace plotter { namespace logic { class Plotter; } }  // Real stuff namespace plotter {     namespace samples {         class Window {             logic::Plotter * mPlotter;             // ...         };     } } 

It greatly reduces the time for compiling also on others compilers. Indeed it applies to all configurations :)

like image 158
Johannes Schaub - litb Avatar answered Sep 21 '22 17:09

Johannes Schaub - litb


Use the Handle/Body pattern (also sometimes known as "pimpl", "adapter", "decorator", "bridge" or "wrapper"). By isolating the implementation of your classes into your .cpp files, they need only be compiled once. Most changes do not require changes to the header file so it means you can make fairly extensive changes while only requiring one file to be recompiled. This also encourages refactoring and writing of comments and unit tests since compile time is decreased. Additionally, you automatically separate the concerns of interface and implementation so the interface of your code is simplified.

like image 40
1800 INFORMATION Avatar answered Sep 19 '22 17:09

1800 INFORMATION