473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

One Big (std::) Header File?

I recently came across the suggestion that it might be beneficial to create
a header file containing all the Standard Headers, and include that in all
the places where declarations from the Standard Library are used - as
opposed to including the specific header containing the declaration. It
was argued that this may improve compilation speeds. Opinions?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #1
12 1754

"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:e7******** ************@sp eakeasy.net...
I recently came across the suggestion that it might be beneficial to create
a header file containing all the Standard Headers, and include that in all
the places where declarations from the Standard Library are used - as
opposed to including the specific header containing the declaration. It
was argued that this may improve compilation speeds. Opinions?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell


I don't think so. All the headers will be compiled for each cpp file that
includes that "super" header file. And not all the code inside is useful.
Include only the necessary headers.

Catalin
Jul 22 '05 #2

"Catalin Pitis" <ca***********@ iquestint.com.r enameme> wrote in message
I don't think so. All the headers will be compiled for each cpp file that
includes that "super" header file. And not all the code inside is useful.
Include only the necessary headers.


And what happens in the case of precompiled headers ?

Sharad
Jul 22 '05 #3
Catalin Pitis wrote:
I don't think so. All the headers will be compiled for each cpp file that
includes that "super" header file. And not all the code inside is useful.
Include only the necessary headers.

Catalin


That is the conventional wisdom. The counter argument has to do with the
use of precompiled headers. I don't understand all the idiosyncracies of
that technology, but the way it was explained, the compiler that supports
pre-compiled headers can skip everything up to the first line that it
hasn't seen before (or something like that). So the usefulness of the
technique will be implementation dependent. I don't know how widespread
support for pre-compiled headers is. GCC just introduced it, and I am not
able to use the latest version for anything that needs to play nicely with
the KDE I'm running.

I do know some things such as the KDE can currently take the better part of
24 hours to build on a decent system. OSG can be a slow build as well.
Anything to improve the build times will be welcomed by me.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #4

"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:lp******** ************@sp eakeasy.net...
Catalin Pitis wrote:
I don't think so. All the headers will be compiled for each cpp file that
includes that "super" header file. And not all the code inside is useful.
Include only the necessary headers.

Catalin


That is the conventional wisdom. The counter argument has to do with the
use of precompiled headers.


Precompiled headers still apply to only the necessary headers, so there
should be no difference between including one big "root" header file and
including only the necessary header files. However, since the headers
contain templates, I'm not sure how this influences the compiling speed.

Catalin
Jul 22 '05 #5
Catalin Pitis wrote:
Precompiled headers still apply to only the necessary headers, so there
should be no difference between including one big "root" header file and
including only the necessary header files.
That is another alternative that was suggested. If I understand what the
authors were saying, the idea is to put all the (standard) headers you use
in the whole project and put them in a shared header file.
However, since the headers
contain templates, I'm not sure how this influences the compiling speed.


Hence my comment about not fully understanding the notion of pre-compiled
headers.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #6

"Steven T. Hatton" <su******@setid ava.kushan.aa> schrieb im Newsbeitrag
news:lp******** ************@sp eakeasy.net...
Catalin Pitis wrote:
I don't think so. All the headers will be compiled for each cpp file that includes that "super" header file. And not all the code inside is useful. Include only the necessary headers.

Catalin
That is the conventional wisdom. The counter argument has to do with the
use of precompiled headers. I don't understand all the idiosyncracies of
that technology, but the way it was explained, the compiler that supports
pre-compiled headers can skip everything up to the first line that it
hasn't seen before (or something like that). So the usefulness of the
technique will be implementation dependent. I don't know how widespread
support for pre-compiled headers is. GCC just introduced it, and I am not
able to use the latest version for anything that needs to play nicely with
the KDE I'm running.

I do know some things such as the KDE can currently take the better part

of 24 hours to build on a decent system. OSG can be a slow build as well.
Anything to improve the build times will be welcomed by me.


In general you should only include the headers that are really required,
although with precompiled headers the story is a little different as you
say. If your build process is still too slow, have you thought about a
parallel build?

Cheers
Chris

Jul 22 '05 #7
Chris Theis wrote:
In general you should only include the headers that are really required,
although with precompiled headers the story is a little different as you
say.
I'm inclined to take the approach of creating a project_std.hh that contains
the standard headers used by the entire project. I don't like the idea all
that much. I very much believe in isolating components as much as
possible. OTOH, if compile times are going to be sensitive to the order in
which headers are included, trying to manage that on a file-by-file basis
throughout a project is probably a bad idea.
If your build process is still too slow, have you thought about a
parallel build?


That depends what you mean. I kick of multiple processes when I build, but
I haven't attempted sharing the load between systems. I don't know how
much getting my hyperthreading to work might impact the build times. As I
said in another post, I'm not able to really experiment with the recently
introduced pre-compiled header support in GCC, so I can't comment on
whether it would make a significant difference. I do believe the KDE folks
may have done some things to speed up the build process. But I haven't
been building the entire cvs image lately, so that's not an immediate
issue.

--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #8
Steven T. Hatton posted:
I recently came across the suggestion that it might be beneficial to
create a header file containing all the Standard Headers, and include
that in all the places where declarations from the Standard Library are
used - as opposed to including the specific header containing the
declaration. It was argued that this may improve compilation speeds.
Opinions?


With precompiled headers, yes.

Sounds like a good idea for when you're actually writing and testing the
program, but once I'd have finished it, or if I was distributing the code,
I'd go back and just select the pertinent headers.
-JKop
Jul 22 '05 #9

"Steven T. Hatton" <su******@setid ava.kushan.aa> schrieb im Newsbeitrag
news:A-*************** *****@speakeasy .net...
Chris Theis wrote:
In general you should only include the headers that are really required,
although with precompiled headers the story is a little different as you
say.
I'm inclined to take the approach of creating a project_std.hh that

contains the standard headers used by the entire project. I don't like the idea all that much. I very much believe in isolating components as much as
possible. OTOH, if compile times are going to be sensitive to the order in which headers are included, trying to manage that on a file-by-file basis
throughout a project is probably a bad idea.
If your build process is still too slow, have you thought about a
parallel build?
That depends what you mean. I kick of multiple processes when I build,

but I haven't attempted sharing the load between systems. I don't know how
much getting my hyperthreading to work might impact the build times. As I
said in another post, I'm not able to really experiment with the recently
introduced pre-compiled header support in GCC, so I can't comment on
whether it would make a significant difference. I do believe the KDE folks may have done some things to speed up the build process. But I haven't
been building the entire cvs image lately, so that's not an immediate
issue.


What I meant by building in parallel is load-sharing. Unfortunately I only
know tools under windows that will do this for you in a comfortable way and
I have no experience doing this under linux. However, a quick google showed
that this seems to be a common approach at the companies providing linux
distributions. IMHO this is the only way to speed up your compilation
process if you cannot apply precompiled headers. In case you find another
solution (or a tool to perform comfortable parallel builds under linux) I'd
be happy if you let me know.

Cheers
Chris
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3441
by: Andy Skypeck | last post by:
I am looking for some validation against a dubious coding practice that prevails where I work. C types defined in types.h (Linux) or stdint.h (Windows, C99?) are used as if they belong to the C++ standard namespace. std::uint8_t instead of uint8_t std::uint32_t instead of uint32_t .... I don't think the use of std:: is correct. Nowhere...
2
2330
by: ash | last post by:
Hi, I'm getting started with STL, and am stuck at creating a map container. I checked one of the texts and found a code in there. To make it simple, i wrote the following: #include <iostream.h> #include <string.h> #include <map>
3
14227
by: JKop | last post by:
I'm writing a ".cpp" and ".hpp" combination. The ".hpp" just contains one sole function declaration. The ".cpp" makes use of the function "std::strlen" and the type "std::size_t".
8
4902
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using namespace std;' unless the std namespace was declared first. This triggered my curiosity, and I tried to find out what the ANSI C++ standard had...
9
10263
by: Mathieu Malaterre | last post by:
Hello, This thread follow my previous one on the gcc mailing list. Basically I -still- have a problem in my code. I define in a header file: static const std::string foo = "bar"; Which not only seems to be a bad practice but also creates a bug on MacOSX panther (gcc 3.3).
8
9171
by: Patrick Kowalzick | last post by:
Dear NG, I would like to change the allocator of e.g. all std::strings, without changing my code. Is there a portable solution to achieve this? The only nice solution I can think of, would be a namespace and another typedef to basic_string: namespace my_string {
5
8673
by: ma740988 | last post by:
Consider the source: # include <iostream> # include <string> # include <fstream> # include <vector> # include <sstream> using namespace std;
9
3757
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in code. for example, this is bad practice: header.h #include <string> using std::string;
5
2814
by: Pradeep | last post by:
Hi All, I am facing some problem using istream_iterator for reading the contents of a file and copying it in a vector of strings.However the same thing works for a vector of integers. The code that doesn't work is std::vector<std::stringvecStr; std::ifstream fstrRead("Test.txt");
4
1899
by: 322322 | last post by:
Could anybody tell where is the namespace std file ? Thanks a lot ! namespace::std{ ..... .... }
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.