473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Polymorphism, again

Hi
I run into a quite weird problem yesterday.

I've got a complex class (let's call it A) which is the last branch of a
deep tree. It has several virtual methods. In a separate module I define a
hundred of different sibling classes, all inherited from A and each one
having just a constructor and a few one-liners, mainly for re-cast. They
don't override any virtual method.

Well, when I compile the new module I get a *huge* object file
(fair) but even with a static linking the final application is huge as
well.

What's in that object file? I know that polymorphism adds a virtual
table to each class, but here I've got several hundreds Kbytes of
overhead for one hundred classes. Isn't it too much? What does the
compiler do?

BTW, what's a good profiler targeted at minimization of code size?

PS: I use gnu g++ and yes, everything is stripped out and I optimize for
size.
Jul 22 '05 #1
3 1121
Legrandin wrote:
Hi
I run into a quite weird problem yesterday.

I've got a complex class (let's call it A) which is the last branch
of a deep tree. It has several virtual methods. In a separate module
I define a hundred of different sibling classes, all inherited from A
and each one having just a constructor and a few one-liners, mainly
for re-cast. They don't override any virtual method.

Well, when I compile the new module I get a *huge* object file
(fair) but even with a static linking the final application is huge as
well.

What's in that object file? I know that polymorphism adds a virtual
table to each class, but here I've got several hundreds Kbytes of
overhead for one hundred classes. Isn't it too much? What does the
compiler do?

BTW, what's a good profiler targeted at minimization of code size?

PS: I use gnu g++ and yes, everything is stripped out and I optimize
for size.


IIRC g++ has a fair warning, that it may not be able to remove duplicate
code, if the linker being used does not support it. So it may be, that for
every object, into which those headers with the million little A-derived
classes get included, will have a million Vtables. My suggestion is to
instruct your linker to make a map file and look at that, and also that
(until you know what makes it big) you consult a g++ newsgroup/list for
further assistance. Then, when you will know what C++ construct makes it
big, it may be possible to find an alternative solution.

--
Attila aka WW
Jul 22 '05 #2
Legrandin wrote:
Hi
I run into a quite weird problem yesterday.

I've got a complex class (let's call it A) which is the last branch of a
deep tree. It has several virtual methods. In a separate module I define a
hundred of different sibling classes, all inherited from A and each one
having just a constructor and a few one-liners, mainly for re-cast. They
don't override any virtual method.

Well, when I compile the new module I get a *huge* object file
(fair) but even with a static linking the final application is huge as
well.

What's in that object file? I know that polymorphism adds a virtual
table to each class, but here I've got several hundreds Kbytes of
overhead for one hundred classes. Isn't it too much? What does the
compiler do?

BTW, what's a good profiler targeted at minimization of code size?

PS: I use gnu g++ and yes, everything is stripped out and I optimize for
size.

A newsgroup appropriate for your OS/compiler is probably more ontopic,
but anyway. You have some large code that perhaps get inlined in each of
these classes ? Get a lot of template instantiation ?
nm -C , objdump,readelf are good tools to examine .o files, atleast if
you're on platforms that uses ELF.(most *nixes)
Jul 22 '05 #3
On Wed, 06 Oct 2004 12:03:12 +0300, Attila Feher wrote:
IIRC g++ has a fair warning, that it may not be able to remove duplicate
code, if the linker being used does not support it. So it may be, that for
every object, into which those headers with the million little A-derived
classes get included, will have a million Vtables. My suggestion is to
instruct your linker to make a map file and look at that, and also that
(until you know what makes it big) you consult a g++ newsgroup/list for
further assistance. Then, when you will know what C++ construct makes it
big, it may be possible to find an alternative solution.


That's the wisest thing to do and I've already had a look at linker information
but there are so many lines that it's really difficult to spot the problem.
I hoped to find some utility to re-order and translate to an human readble
format but I haven't found anything on the net. I'll try to come out with
some script to do the job.

On my news-server there are no groups dealing with g++, I'm sorry if my post
appeared as an OT. I secretly thought that this problem could be
more theoretical. As a matter of fact, with the Intel compiler I got even
worse results although I didn't play much with it.

To Nils: neither inlines nor templates at all in my case.

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
10
by: Danny Ni | last post by:
Hi, I was asked a question in a recent interview, where in ASP.Net is polymorphism used? I got differrent answers from different people, One said ToString() method because it is working for...
35
by: JKop | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en- us/vccore98/HTML/_core_using_strict_type_checking.asp Pay particular attention to: The types WPARAM, LPARAM, LRESULT, and void *...
30
by: Richard Tappenden | last post by:
Hi! I'm struggling a bit with Polymorphism in vb.net. There is something I know I can do in C++, but I cannot seem to do it in vb.net (or c# for that matter). Basically, I have an abstract...
13
by: Fao | last post by:
Hello, I am having some problems with inheritance. The compiler does not not return any error messages, but when I execute the program, it only allows me to enter the number, but nothing else...
18
by: Seigfried | last post by:
I have to write a paper about object oriented programming and I'm doing some reading to make sure I understand it. In a book I'm reading, however, polymorphism is defined as: "the ability of two...
11
by: chsalvia | last post by:
I've been programming in C++ for a little over 2 years, and I still find myself wondering when I should use polymorphism. Some people claim that polymorphism is such an integral part of C++,...
8
by: weird0 | last post by:
Can anyone explain briefly what is the difference between inheritance and polymorphism? i read and seem to forget it again and again... Can anyone along with good examples of c# explain the...
1
weaknessforcats
by: weaknessforcats | last post by:
Introduction Polymorphism is the official term for Object-Oriented Programming (OOP). Polymorphism is implemented in C++ by virtual functions. This article uses a simple example hierarchy which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.