Large Object Files

I have a library that I build using MSVC++ 6.0.  It contains a lot of classes, but most of them are very small.  When I build even the small classes, I get object files that are over 800KB in size!  My library ends up being 131MB (and that is for the Release library).  Most of these small classes subclass another class that is 165KB in size which subclasses yet another class 5kb in size.   I tried to build for mimum size and it really doesn't help much.  Does it seem reasonable that my .obj files would be so large.

Thanks in advance for any help.
jribbleAsked:
Who is Participating?
 
e_tadeuConnect With a Mentor Commented:
I think it must be one of these two:

1) You are using too much templated code, and too much template instantiations
2) You are including a header from your .cpp files with too much static data on it

Also, try to disable header pre-compiling.
0
 
jkrCommented:
Do you have some more information? Is this a static library? What kind of code is in there, what does it do? What are your compiler/linker settings?
0
 
jribbleAuthor Commented:
Here is the information requested (let me know if you need more specific information). Thanks!

Yes, this is a static library.  It includes functions from another static library.  

From Project Options:

/nologo /MD /W3 /GX /O1 /I "\source\gpmqNT\Common\MesCommonLib\Versions\v2.8.0\Include" /I ".\Include" /I "X:\source\gpmqNT\UniversalCfg" /I "X:\source\gpmqNT\Logger\Include" /I "X:\source\utility\encdec\encdec2" /I "\source\gpmqNT\Common\MesReportLib\Versions\v2.4.1\Include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"Release/GPMQDLL.pch" /YX"stdafx.h" /Fo"Release/" /Fd"Release/" /FD /c

Most of the classes are used to map a database table.  These objects can be created and based on the columns, SQL is generated to insert or update rows in our DB2 database.  Here is a sample (note they do not contain a lot of code, but do subclass another larger class CDomain).

// BinFeetOfAir.cpp: implementation of the CBinFeetOfAir class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BinFeetOfAir.h"
#include "Columns.h"
#include "Brokers.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

Sample .hpp file
// BinFeetOfAir.h: interface for the CBinFeetOfAir class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_BINFEETOFAIR_H__E55DA8F6_C198_424B_8ED7_E17E945A86F4__INCLUDED_)
#define AFX_BINFEETOFAIR_H__E55DA8F6_C198_424B_8ED7_E17E945A86F4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Domain.h"
#include "Domains.h"

class __declspec(dllexport)CBinFeetOfAir : public CDomain  
{
DECLARE_DYNCREATE( CBinFeetOfAir )
public:
      CBinFeetOfAir();
      virtual ~CBinFeetOfAir();

};

#endif // !defined(AFX_BINFEETOFAIR_H__E55DA8F6_C198_424B_8ED7_E17E945A86F4__INCLUDED_)


Sample .cpp file
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE( CBinFeetOfAir, CDomain )

CBinFeetOfAir::CBinFeetOfAir()
{
      addColumn(new CColumn(INTEGER_COLUMN,this,INGREDIENT_BIN_NUMBER));
      addColumn(new CColumn(INTEGER_COLUMN,this,FEET_OF_AIR));
      addColumn(new CColumn(DOUBLE_COLUMN,this,BUSHELS));
      setBrokerId(BIN_FEET_OF_AIR_BROKER);
      setDomainType(BIN_FEET_OF_AIR_DOMAIN);
      addDomainKeyID(INGREDIENT_BIN_NUMBER);
      addDomainKeyID(FEET_OF_AIR);
      setRunTimeClass(RUNTIME_CLASS(CBinFeetOfAir));
}

CBinFeetOfAir::~CBinFeetOfAir()
{

}
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
jkrCommented:
The linker settings would be helpful also ;o)
0
 
jribbleAuthor Commented:
From the Library tab, here are the Project Options:
/nologo /out:"Release\GPMQDLL.lib"

Is that what you were looking for - since this is a static library, there isn't much.
0
 
jkrCommented:
Hmm, odd. Do al the onject files become that large? What does 'dumpbin' report about the entries in the .lib?
0
 
jribbleAuthor Commented:
As it turns out, we had a lot (approximatly 600) of the following type of definition in a header file...

const CString BLA_BLA = "BLA_BLA";

What happened with these declarations was that any .cpp file that included the headers defined ALL of these instances of
CString object.

We changed all global CString constant objects to macro definitions that create exactly the same objects dynamically.

Here are the details, based on a small sample code.

OLD:
 base.h contained:
 
 const CString SOME_ID = "SOME_ID";
 
 class CBase {
 public:
   // constructor and destructor.
   // ...
 }

NEW:
 base.h contains:

 #define SOME_ID CString(CBase::_SOME_ID)
 
 class CBase {
 public:
 static const char* _SOME_ID;
 public:
   // constructor and destructor.
   // ...
 }

 added to base.cpp:
 const char* CBase::_SOME_ID = "SOME_ID";

Maybe there was a way to do this simpler, e.g. by only one macro declaration:
 #define SOME_ID CString("SOME_ID")

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.