Solved

Large Object Files

Posted on 2006-06-27
7
227 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:jribble
  • 3
  • 3
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16995949
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
 

Author Comment

by:jribble
ID: 16996084
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
 
LVL 86

Expert Comment

by:jkr
ID: 16996170
The linker settings would be helpful also ;o)
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:jribble
ID: 16996210
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
 
LVL 86

Expert Comment

by:jkr
ID: 16996503
Hmm, odd. Do al the onject files become that large? What does 'dumpbin' report about the entries in the .lib?
0
 
LVL 4

Accepted Solution

by:
e_tadeu earned 500 total points
ID: 17000660
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
 

Author Comment

by:jribble
ID: 17004288
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now