?
Solved

Large Object Files

Posted on 2006-06-27
7
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

777 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