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.
System Programming

Avatar of undefined
Last Comment
bigsteve87

8/22/2022 - Mon
jkr

>>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();
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.
AlexFM

>> Will it hurt the program’s performance to have “#include “MyApp.h” all over the place?

No.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
bigsteve87

ASKER
Ok, good.

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

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
AlexFM

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.
bigsteve87

ASKER
Thanks.  I wanted to make sure that I wasn't unnecessarily bloating my program.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.