473,549 Members | 2,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pimpl or precompiled headers?

Hi,

Now that GCC 3.4 has precompiled headers, I'm thinking I can stop
using pimpls to speed up development time, as it may make life
easier (declaring pimpls takes a long time...)

What are the views of the experienced users of various C++
implementations ? Do precompiled headers allow pimpls to be
avoided while maintaining the same speed up of development time?


--
http://www.it-is-truth.org/
Jul 22 '05 #1
6 2178
Asfand Yar Qazi wrote:
Now that GCC 3.4 has precompiled headers, I'm thinking I can stop
using pimpls to speed up development time, as it may make life
easier (declaring pimpls takes a long time...)

What are the views of the experienced users of various C++
implementations ? Do precompiled headers allow pimpls to be
avoided while maintaining the same speed up of development time?


"Pimpl" is an idiom that one refactors into existing code to compile faster.

Refactors change design while leaving behavior the same. The Pimpl refactor
leaves logical design the same while tweaking physical design, so
translation units needn't see the details of other classes. That prevents
excessive recompiles when you change a highly reused class.

But Pimpl is for emergencies, after a design is committed. C++ was designed
to permit compilation firewalls based on abstract types; Pimpl abstracts a
concrete type.

Robert C. Martin's "Dependency Inversion Principle" describes this design
goal.

http://www.objectmentor.com/resources/articles/dip.pdf

It implies that only classes with a few pure-virtual methods should be
widely re-used. This is both a valid design technique and a system that, in
C++, prevents runaway re-compiles.

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces
Jul 22 '05 #2
> > Now that GCC 3.4 has precompiled headers, I'm thinking I can stop
using pimpls to speed up development time, as it may make life
easier (declaring pimpls takes a long time...)

What are the views of the experienced users of various C++
implementations ? Do precompiled headers allow pimpls to be
avoided while maintaining the same speed up of development time?
"Pimpl" is an idiom that one refactors into existing code to compile faster.


"Pimpl" has at least an additional advantage as discussed by Herb Sutter:
It can lead to exception safe assignment. No precompiled header system
can do this.
C++ was designed
to permit compilation firewalls based on abstract types;


In my opinion, this only holds if you supplement your concrete, derived class
with a factory function - otherwise you've to include the header file
of your derived class into each file, where you create an instance, though
besides this creation step you only need the declaration of the base class.

Personally, I'd prefer Pimpl over precompiled headers because of two
reasons:
- The precompiled header system of many compilers is limited and would
cause additional considerations on usage.
- Often it is sufficient to reduce compile time not to include unnecessary header
files. With precompiled headers commenting out inclusion somewhere doesn't
necessarily causes a compile error, if the file is needed, so you have less
support by your compiler.

Cheers,
Philipp.
Jul 22 '05 #3
* "Phlip" <ph*******@yaho o.com> schriebt:
It implies that only classes with a few pure-virtual methods should be
widely re-used. This is both a valid design technique and a system that, in
C++, prevents runaway re-compiles.


You've posted this rubbish before. So in your opinion the standard library
is all wrong. Duh, idiot.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #4
"Asfand Yar Qazi" <im_not_giving_ it_here@i_hate_ spam.com> wrote in message
Now that GCC 3.4 has precompiled headers, I'm thinking I can stop
using pimpls to speed up development time, as it may make life
easier (declaring pimpls takes a long time...)

What are the views of the experienced users of various C++
implementations ? Do precompiled headers allow pimpls to be
avoided while maintaining the same speed up of development time?


If you want reference counting, then surely you have to use the pimpl.

In principle your question is good, but I haven't done measurements so can't
say. Let's see what others say. In principle, it should be faster, so as
soon as the code is stable, we can start to use pre-compiled headers.
Jul 22 '05 #5
* "Siemel Naran" <Si*********@RE MOVE.att.net> schriebt:
"Asfand Yar Qazi" <im_not_giving_ it_here@i_hate_ spam.com> wrote in message
Now that GCC 3.4 has precompiled headers, I'm thinking I can stop
using pimpls to speed up development time, as it may make life
easier (declaring pimpls takes a long time...)

What are the views of the experienced users of various C++
implementations ? Do precompiled headers allow pimpls to be
avoided while maintaining the same speed up of development time?


If you want reference counting, then surely you have to use the pimpl.

In principle your question is good, but I haven't done measurements so can't
say. Let's see what others say. In principle, it should be faster, so as
soon as the code is stable, we can start to use pre-compiled headers.


The pimpl idiom is not necessary for speeding up compiles; all that's needed
for that is Lakos-style external include guards.

The pimpl idiom is not necessary for reference counting; it isn't even related.

I think perhaps pimpl is being used above in two different senses, both of them
different from the usual C++ meaning of class-with-only-pointer-to-implementation
in header file, class-with-implementation (plus header file dependencies for that
implementation) in the implementation file.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #6
"Alf P. Steinbach" <al***@start.no > wrote in message
* "Siemel Naran" <Si*********@RE MOVE.att.net> schriebt:
"Asfand Yar Qazi" <im_not_giving_ it_here@i_hate_ spam.com> wrote in message
Now that GCC 3.4 has precompiled headers, I'm thinking I can stop
using pimpls to speed up development time, as it may make life
easier (declaring pimpls takes a long time...)

What are the views of the experienced users of various C++
implementations ? Do precompiled headers allow pimpls to be
avoided while maintaining the same speed up of development time?
If you want reference counting, then surely you have to use the pimpl.

In principle your question is good, but I haven't done measurements so can't say. Let's see what others say. In principle, it should be faster, so as soon as the code is stable, we can start to use pre-compiled headers.


The pimpl idiom is not necessary for speeding up compiles; all that's

needed for that is Lakos-style external include guards.
If C.h includes B.h includes A.h, and you change A.h by adding new data
members, then you have to compile not only A.cpp and B.cpp and C.cpp. Had
you used pimpl, you'd have to compile the same or fewer files, the number
depending on whether you changed A.cpp only (to add new data members and use
them in the implementation) or A.h also (to add new public/protected member
functions to expose the new data members), depending on whether B.h includes
A.h or only B.cpp includes A.h, etc. In the common case of adding data
members only to A.cpp, for optimization or whatever reasons, you now don't
have to compile B.cpp and C.cpp.

The Lakos style redundant include guards are, they say, no longer necessary
in today's modern compilers.
The pimpl idiom is not necessary for reference counting; it isn't even related.

It is similar. In traditional pimpl you declare a struct Class::Imp in the
header file, and Class contains a std::auto_ptr<I mp> or Imp*, and you define
Class::Imp in the cpp file. To add reference counting, just change the
Imp* to a boost::shared_p tr<Imp>. Isn't this similar?
I think perhaps pimpl is being used above in two different senses, both of them different from the usual C++ meaning of class-with-only-pointer-to-implementation in header file, class-with-implementation (plus header file dependencies for that implementation) in the implementation file.


Jul 22 '05 #7

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

Similar topics

1
3649
by: JoeS | last post by:
Is there anyway to share a single pch file between projects in VC 7.0? I have 300+ projects each of which creates its own pch. All projects include the exact same header files in the precompiled header. Its takes about 7 seconds to create the precompiled header for each project. That's 35 minutes spent creating precompiled headers for all...
4
2507
by: Andrew Ward | last post by:
Hi All, I was wondering if it is possible to use precompiled headers without having to include a <stdafx.h> or whatever in every source file. My problem is that I have a project that makes heavy usage of a large third party library which means after pre-processing each translation unit is around 1meg in size. There are reasons though why I...
0
1193
by: Bruno van Dooren | last post by:
Hi, I am working on a dll that exports COM interfaces, and i am having some troubles with the use of precompiled headers. the project compiles always, but if i use /Yu (default: use precompiled header) i get linker error: OPCServer.exp : warning LNK4070: /OUT:OPCServer.dll directive in .EXP differs from output filename...
20
1614
by: Bonj | last post by:
Is it possible to avoid using precompiled headers on files that don't #include "stdafx.h". I have an ATL project,which has got a lot of ATL #includes in its stdafx.h. I now need to add some .c files to this project, that compile as hard raw C - not C++. The .c files obviously won't understand the <atlbase.h> etc that are in the stdafx.h....
1
1200
by: dt | last post by:
Having troubles with my program and i believe it has something to do with my project settings for precompiled headers. This is what i have: my main cpp file, vector.h/cpp and polygon.h/cpp. vector.h includes math, polygon includes vector and gl/gl.h, and main includes windows.h, gl/gl.h, gl/glu.h, gl/glaux.h and polygon.h i've tried...
1
1367
by: Alvo von Cossel I | last post by:
yo, i have a simple hello world win32 console application. it should work but there is an error. here is the most important part of the error: have you forgotten to add #include <stdfx.h> to your source code? stdfx.h is a precompiled header and i have deleted it but vc++ still asks me to include it. how do i change the precompiled...
3
1914
by: Kevin Frey | last post by:
I am working on a test migration of our project to Visual Studio 2005 Beta 2 as a precursor to the availability of the full release of VS2005. The most onerous problem so far concerns the requirement by LINK.EXE that if an object file has used precompiled headers, then the resulting "precompiled header object file" must also be one of the...
34
3672
by: Asfand Yar Qazi | last post by:
Hi, I'm creating a library where several classes are intertwined rather tightly. I'm thinking of making them all use pimpls, so that these circular dependancies can be avoided easily, and I'm thinking of making all these pimpl class declarations public. Reasoning is that since only the code within the ..cc file will need to ever access...
8
1466
by: Abubakar | last post by:
Hi, I am writing some unmanaged c++ code that would need to be compiled in the future using compilers other than vc++. I'm using the feature of vc++ "use precompiled headers", is there going to be any problem if I compile this code on other compilers? I'm asking this because when I use pch *some* of my cpp files has following as there first...
0
7444
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
7711
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
7467
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
7805
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
6039
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
5367
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
3497
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...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.