Link to home
Start Free TrialLog in
Avatar of bigsteve87
bigsteve87

asked on

Including header and accessing classes' effect on release exe’s performance and size in VC6

I want some guidance on how to set up my classes to optimize my program’s speed and size.  I don’t really care about compile time.

My program has alot of large classes with large header files and most new classes I make need one or two functions from at least a dozen of the large classes.  
They are usually the same functions needed across the project.

For example:

class CMyApp : public CWinApp
{
public:
  CString TempDirectory();
…(Tons of other functions)
}

A crapload of other classes need that TempDirectory() function, will it hurt the program’s performance to have “#include “MyApp.h” all over the place?

Should I add some intermediate files to provide access to these common functions?

For example:

Directories.h:
CString TempDirectory();
…(a few other common functions)

Directories.cpp:
“#include “MyApp.h”
CString TempDirectory(){
      return (CMyApp*)AfxGetApp()->TempDirectory();
}
Then just include “Directories.h” everywhere.

Any suggestions and explanations would be appreciated; the project is becoming a mess of header files.
Avatar of jkr
jkr
Flag of Germany image

>>A crapload of other classes need that TempDirectory() function, will it hurt the program’s performance to
>>have “#include “MyApp.h” all over the place?

I don't see a reason to do so:

CMyApp* pApp = (CMyApp*) AfxGetApp();

CString strDir = pApp->TempDirectory();
Avatar of bigsteve87
bigsteve87

ASKER

That was one example, but there are alot of other similar cases.

If I use CMyApp* pApp = (CMyApp*) AfxGetApp(); in a class that does not have “#include “MyApp.h” in the cpp file, I get an error because it does not recognize the class CMyApp.
>> Will it hurt the program’s performance to have “#include “MyApp.h” all over the place?

No.
Ok, good.

So the compiler should ignore the functions that are not used?
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For example, every Windows application has line:
include <windows.h>
which contains thousands of Windows API. Compiler needs some time to scan this file, but executable module contains only calls to API which are actually used, and not to possible Windows API.
Thanks.  I wanted to make sure that I wasn't unnecessarily bloating my program.