Click here to Skip to main content
15,908,901 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Rebuild problem Pin
Max Santos14-Aug-06 7:57
Max Santos14-Aug-06 7:57 
GeneralRe: Rebuild problem Pin
David Crow14-Aug-06 8:06
David Crow14-Aug-06 8:06 
GeneralRe: Rebuild problem Pin
Max Santos14-Aug-06 8:18
Max Santos14-Aug-06 8:18 
AnswerRe: Rebuild problem Pin
Stephen Hewitt14-Aug-06 15:19
Stephen Hewitt14-Aug-06 15:19 
AnswerRe: Rebuild problem Pin
Maximilien14-Aug-06 10:23
Maximilien14-Aug-06 10:23 
GeneralRe: Rebuild problem Pin
Max Santos14-Aug-06 10:40
Max Santos14-Aug-06 10:40 
AnswerRe: Rebuild problem Pin
Joe Woodbury14-Aug-06 12:09
professionalJoe Woodbury14-Aug-06 12:09 
AnswerRe: Rebuild problem Pin
Mike Dimmick15-Aug-06 2:31
Mike Dimmick15-Aug-06 2:31 
Here's a set of techniques in order of increasing risk and diminishing returns:

Start in StdAfx.h, assuming you're using precompiled headers (and the precompiled header has the default configuration; if you're using a different header for PCH, edit that instead). Leave only #includes in this file which are stable (e.g. dependencies on external libraries) or which really do need to be included in absolutely every file. I often see StdAfx.h used as a dumping ground for all headers in a project, which, since all source files include StdAfx.h, causes every file to be recompiled even if a tiny change to an inconsequential header occurs.

If you're not using precompiled headers, consider doing so. The amount of time taken to parse <windows.h> is huge because it includes most of the files in the Platform SDK Include directory, which as of VS2005 is 46MB. MFC and ATL headers include windows.h.

Once you've edited down StdAfx.h, you'll probably have a load of compilation errors. Just get it to compile for now, by including only those headers you actually need. For class members, in the header, forward-declare those classes which are only referenced by pointer or by reference; #include those which you must.

In each header, look for uses of classes and structs defined outside that header. If a class only appears in pointer and/or reference declarations, it can be forward-declared rather than the corresponding header being #included. The source file that actually implements the functions manipulating the pointer or reference will need to #include the header declaring the class.

Look out for implementation of methods in class declarations. These should be a) trivial and b) stable, and ideally not reference the implementation of other classes. Any that aren't should be stripped out and placed in a source file. Method implementations in class declarations have the additional semantics of being considered for inlining. Generally you can get away with not inlining most of this code with very little performance impact. MFC uses a trick of keeping performance-critical routines in files with a .inl extension: in debug builds, the matching _AFXxxx_INLINE macro expands to nothing and the file is #included in the corresponding .cpp file, while in release builds the macro expands to inline and the file is #included in the corresponding header, which causes the code to be inlined if required.

If an otherwise stable class has a class member which is unstable (the declaration constantly changing), consider changing it from being a contained member to a pointer to that class, then forward-declare that class and remove the #include.

Consider replacing parameters of class or struct type with a const reference. This also saves a call to the copy constructor.

Look for overuse of inheritance. When inheriting, the full declaration of a base class is required at the point of declaration of a derived class. If the base class implementation details change, it will impact all the derived classes. It may be better to declare an abstract class containing only the public interface, and derive concrete classes from the interfaces. Often inheritance is used unnecessarily, and composition - reimplementing the derived class in terms of its former base class - is a better technique.

If you don't want to incur the overhead of virtual functions when trying to hide the implementation details of a class (for example, there would otherwise not be any virtual functions), consider the so-called 'pimpl idiom'. Here you move all members that are unstable into a separate 'implementation' class, then replace all those members in the original class with a single 'pointer-to-implementation' member.

Stability. What an interesting concept. -- Chris Maunder

GeneralRe: Rebuild problem Pin
Max Santos17-Aug-06 10:57
Max Santos17-Aug-06 10:57 
Questionhow i can whrite text on another form my program Pin
shortwave14-Aug-06 7:32
shortwave14-Aug-06 7:32 
AnswerRe: how i can whrite text on another form my program Pin
David Crow14-Aug-06 7:55
David Crow14-Aug-06 7:55 
AnswerRe: how i can whrite text on another form my program Pin
Hamid_RT14-Aug-06 8:08
Hamid_RT14-Aug-06 8:08 
GeneralRe: how i can whrite text on another form my program Pin
shortwave15-Aug-06 3:42
shortwave15-Aug-06 3:42 
GeneralRe: how i can whrite text on another form my program Pin
Hamid_RT15-Aug-06 7:57
Hamid_RT15-Aug-06 7:57 
Questionlist view Pin
TAREQ F ABUZUHRI14-Aug-06 7:29
TAREQ F ABUZUHRI14-Aug-06 7:29 
Questiondialog, radio and combo box Pin
blue i14-Aug-06 7:14
blue i14-Aug-06 7:14 
AnswerRe: dialog, radio and combo box Pin
David Crow14-Aug-06 7:47
David Crow14-Aug-06 7:47 
AnswerRe: dialog, radio and combo box Pin
Hamid_RT14-Aug-06 7:53
Hamid_RT14-Aug-06 7:53 
Questionugly casting warning DWORD to PVOID Pin
hunter1314-Aug-06 6:06
hunter1314-Aug-06 6:06 
AnswerRe: ugly casting warning DWORD to PVOID Pin
Joe Woodbury14-Aug-06 12:17
professionalJoe Woodbury14-Aug-06 12:17 
AnswerRe: ugly casting warning DWORD to PVOID Pin
Mike Dimmick14-Aug-06 14:20
Mike Dimmick14-Aug-06 14:20 
GeneralRe: ugly casting warning DWORD to PVOID Pin
hunter1315-Aug-06 23:35
hunter1315-Aug-06 23:35 
GeneralRe: ugly casting warning DWORD to PVOID Pin
Mike Dimmick16-Aug-06 15:44
Mike Dimmick16-Aug-06 15:44 
GeneralRe: ugly casting warning DWORD to PVOID Pin
hunter1316-Aug-06 20:37
hunter1316-Aug-06 20:37 
Questionspecifying source files for nmake Pin
rana7414-Aug-06 5:59
rana7414-Aug-06 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.