Solved

Large Object Files

Posted on 2006-06-27
7
229 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

911 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

18 Experts available now in Live!

Get 1:1 Help Now