Single Compilation Unit

Single Compilation Unit

Single Compilation Unit is a C/C++ technique which reduces compilation time and aids the compiler to perform program optimization even when compiler itself is lacking support for "whole program optimization" or precompiled headers.

Purpose

Usually a C/C++ development environment assumes that .c/.cpp source files (translation units) are preprocessed and translated separately by the compiler to object (.o or .obj) files, which can then be linked together to create an executable file or library. This leads to multiple passes being performed on common header files and, with C++, multiple template instantiations of the same templates in different translation units. The Single Compilation Unit technique uses preprocessor directives to "glue" different translation units together at compile-time, not link-time. This reduces the overall build time, but increases the build time required after making minor changes to any source file included in a Single Compilation Unit. So this technique is appropriate for some modules which consist of infrequently modified source files.

SCU also allows an optimizer to trace deeper relations between functions, therefore allowing optimizations such as inlining. It also helps avoiding implicit code bloat due to exceptions, side effects, and register allocation, which are generally overlooked by the classic scheme of using separate modules, and not always achieved by the use of precompiled headers.

Usage

For example, if you have the source files foo.cpp and bar.cpp, they can be placed in a Single Compilation Unit as follows:


#include "foo.cpp"
#include "bar.cpp"
Suppose foo.cpp and bar.cpp are:
//foo.cpp
#include // A large, standard header
#include "bar.hpp" // Declaration of function 'bar'

int main() // Definition of function 'main'{ bar();}

//bar.cpp
#include // The same large, standard header

void bar() // Definition of function 'bar'{ ...}

Now the standard header file ('iostream') is compiled only once, and function 'bar' may be inlined into function 'main', despite being from another module.

ee also

*Precompiled headers
*C/C++ preprocessor
*Whole program optimization


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • single — {{Roman}}I.{{/Roman}} noun 1 CD, tape, etc. ADJECTIVE ▪ best selling, hit, smash ▪ number one, top ten ▪ debut, first …   Collocations dictionary

  • Hello! Project Shuffle Unit Mega Best — Compilation par divers artistes du Hello! Project Sortie 10 décembre 2008 Enregistrement Japon Genre J Pop Format …   Wikipédia en Français

  • Paul Oxley's Unit — was popular rock band in Finland in the 1980s.The bands vocalist and songwriter was a man from Manchester, named Malcolm Campbell, or in his stage name, Paul Oxley. Playing the keyboards was Brian Hammond, but he wasn t playing yet in the first… …   Wikipedia

  • Armed Police Unit Gallop — Infobox VG title = Armed Police Unit Gallop caption = developer = Irem publisher = Irem release = 1991 genre = Scrolling shooter modes = Single player cabinet = Upright platforms = Arcade input = 8 way joystick, 2 buttons arcade system= Irem M 84 …   Wikipedia

  • Où veux-tu qu'je r'garde ? (single) — Où veux tu qu je r garde ? est le premier single du groupe de rock français Noir Désir sorti en 1987. Il est seulement en France et en format vinyle. Il comporte une face B chantée en anglais, Lola. Les deux chansons appaîtront sur le… …   Wikipédia en Français

  • Ou veux-tu qu'je r'garde ? (single) — Où veux tu qu je r garde ? (single) Portail du rock Principaux courants Scènes régionales Groupes et musiciens Par instrument …   Wikipédia en Français

  • Où veux-tu qu'je r'garde ? single — Où veux tu qu je r garde ? (single) Portail du rock Principaux courants Scènes régionales Groupes et musiciens Par instrument …   Wikipédia en Français

  • Lost (single) — Lost Single par Noir Désir extrait de l’album Des visages des figures Face A Lost Face B Baiser cannibal Son style 3 Sortie  2002 Paroli …   Wikipédia en Français

  • SCU — may refer to: * Senatus consultum ultimum, something tantamount to martial law in the times of the Roman Republic * Southern Cross University, in Lismore, NSW, Australia * Santa Clara University, in Santa Clara, California, United States *… …   Wikipedia

  • Precompiled header — In computer programming, a pre compiled header is a technique used by some C or C++ compilers to reduce compilation time. OverviewIn the C and C++ programming languages, a header file is a file whose text may be automatically included in another… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”