473,503 Members | 1,700 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 1749

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:e7********************@speakeasy.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.renameme> 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******@setidava.kushan.aa> wrote in message
news:lp********************@speakeasy.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******@setidava.kushan.aa> schrieb im Newsbeitrag
news:lp********************@speakeasy.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******@setidava.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

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:e7********************@speakeasy.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?


I think that's an attempt to avoid (some) thinking while writing
a program. I don't like it at all.

-Mike
Jul 22 '05 #11
Mike Wahler wrote:

"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:e7********************@speakeasy.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?


I think that's an attempt to avoid (some) thinking while writing
a program. I don't like it at all.

-Mike

I won't say they sold me on the idea yet, but I won't accuse these guys of
trying to duck too much thinking. See §6.5:

http://www.josuttis.com/tmplbook/

I was rather surprised when I read the discussion. When I reread it just
now, I realized the recommendation seems stronger than I had first taken it
to be.
--
"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 #12
Chris Theis wrote:


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


As is typical of me, I had the software installed and ready to go, I just
never took the time to read the documentation. I've also been reluctant to
mess with trying to get all my versions synchronized between systems. For
various reasons I tend to want different configurations on different boxes.

This is from the people who implemented SMBFS for Linux:

http://distcc.samba.org/
1. For each machine, download distcc, unpack, and do
./configure && make && sudo make install
2. On each of the servers, run distccd --daemon, with --allow options to
restrict access.
3. Put the names of the servers in your environment:
export DISTCC_HOSTS='localhost red green blue'
4. Build!
cd ~/work/linux-2.4.19; make -j8 CC=distcc

The install and config was actually _easier_ than what's described above.

I can't comment on the ROI yet. I can say my old klunker hasn't worked so
hard in years. I'm not really sure why it is spending so much time hitting
the harddrive, but I have an ancient 300 meg Western Digital I use for
extra swap space, and it is going crazy. It may turn out that it's so
slow, it actually slows down other build processes if it blocks. I have
another system I'm upgrading so I can tie it in as well. Also not a top of
the line.

I've been using this for a while:
http://ccache.samba.org/

It doesn't work magic, but it does seem to help.

--
"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 #13

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

Similar topics

5
3436
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++...
2
2324
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...
3
14216
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
4894
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...
9
10255
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...
8
9162
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...
5
8668
by: ma740988 | last post by:
Consider the source: # include <iostream> # include <string> # include <fstream> # include <vector> # include <sstream> using namespace std;
9
3748
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...
5
2805
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...
4
1895
by: 322322 | last post by:
Could anybody tell where is the namespace std file ? Thanks a lot ! namespace::std{ ..... .... }
0
7083
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...
0
7278
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,...
1
6988
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...
0
5578
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,...
1
5011
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...
0
4672
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...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
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 ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.