473,409 Members | 1,945 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,409 software developers and data experts.

RTTI overhead

Hello there,
I would like to know what overheads there are to think of when using RTTI. I
understand that enabling RTTI increases the sizes of the classes, but not
the objects themselves. This doesn't sound too bad.
What I'm worried about is whether there is a general performance overhead
caused by enabling RTTI, such as enabling exceptions makes a C++ program
slower even when there are no exceptions actually used.
Are there similar considerations in the case of RTTI?

I am using VC++7.1, but I'm also interested about this in general.

Thx, Agoston
Jul 22 '05 #1
9 4604
Agoston Bejo wrote:
Hello there,
I would like to know what overheads there are to think of when using RTTI. I
understand that enabling RTTI increases the sizes of the classes, but not
the objects themselves. This doesn't sound too bad.
Polymorphic objects (those with virtual functions) are slightly larger
typically because they contain a pointer to the class specific information
(vtable pointer).
What I'm worried about is whether there is a general performance overhead
caused by enabling RTTI, such as enabling exceptions makes a C++ program
slower even when there are no exceptions actually used.
Are there similar considerations in the case of RTTI?

As far as C++ is concerned there is no such thing as turning RTTI off.
This is a defect in your compiler. And boy if you ever access a function
requiring RTTI you'll blow up at runtime (believe me I know).

C++ is very careful NOT to incur performance hits on features you are't
using, so if you have a non-polymorphic class (no virtual functions), then
the overhead disappears. Once you have a virtual function, which really
needs the overhead to work, then all the other RTTI-related features like
dynamic cast and dynamic typeid will work with that class.
Jul 22 '05 #2
Agoston Bejo wrote:
I would like to know what overheads there are to think of when using RTTI. I
understand that enabling RTTI increases the sizes of the classes, but not
the objects themselves. This doesn't sound too bad.
What I'm worried about is whether there is a general performance overhead
caused by enabling RTTI, such as enabling exceptions makes a C++ program
slower even when there are no exceptions actually used.
Are there similar considerations in the case of RTTI?

I am using VC++7.1, but I'm also interested about this in general.


If you can create two programs where one _uses_ RTTI and the other does
not, and otherwise they are _absolutely_ the same, then you can measure
the _real_ overhead. However, logically, that's impossible. If your code
does not use RTTI, why enable RTTI? If after you enable RTTI in your
program that does not use it you notice that it's slower, the you've
created something to measure, but what value does that measurement have?

Also, keep in mind, such overheads cannot be made generic, since they
depend greatly on the compiler/platform/libraries used. If I somehow
measure the "overhead" of using RTTI in my program/compiler combination,
what knowledge can you derive from that for your program/compiler
combination?

See my point?

Victor
Jul 22 '05 #3
Agoston Bejo wrote:
Hello there,
I would like to know what overheads there are to think of when using RTTI.
I understand that enabling RTTI increases the sizes of the classes, but
not the objects themselves. This doesn't sound too bad.
What I'm worried about is whether there is a general performance overhead
caused by enabling RTTI, such as enabling exceptions makes a C++ program
slower even when there are no exceptions actually used.
Are there similar considerations in the case of RTTI?


Basically, it depends on the compiler, but usually no, there is no overhead.

Jul 22 '05 #4
Agoston Bejo wrote:
Hello there,
I would like to know what overheads there are to think of when using RTTI. I
understand that enabling RTTI increases the sizes of the classes, but not
the objects themselves. This doesn't sound too bad.
What I'm worried about is whether there is a general performance overhead
caused by enabling RTTI, such as enabling exceptions makes a C++ program
slower even when there are no exceptions actually used.
Are there similar considerations in the case of RTTI?

"Enabling" exceptions in nowadays implementations should incur no
overheads (unless an exception is thrown in which case what should be
considered as overhead is not clear).
RTTI means "run-time type identification. That means you have to perform
run-time checks to find the type of an object. These checks are the
overhead.
In C++, there is the rule "what you do not use, you do not pay for". So
if you do not use RTTI you do not pay any run-time checks cost.
Thus the phrase "enable" does not make sense.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #5
Ioannis Vranos wrote:
Agoston Bejo wrote:
Hello there,
I would like to know what overheads there are to think of when using
RTTI. I understand that enabling RTTI increases the sizes of the classes,
but not the objects themselves. This doesn't sound too bad.
What I'm worried about is whether there is a general performance overhead
caused by enabling RTTI, such as enabling exceptions makes a C++ program
slower even when there are no exceptions actually used.
Are there similar considerations in the case of RTTI?

"Enabling" exceptions in nowadays implementations should incur no
overheads (unless an exception is thrown in which case what should be
considered as overhead is not clear).


Maybe it shouldn't but often, it does incur an overhead in code size, which
indirectly affects performance through higher cache load.
In C++, there is the rule "what you do not use, you do not pay for". So
if you do not use RTTI you do not pay any run-time checks cost.
Thus the phrase "enable" does not make sense.


Well, if you disable it, you'll get a compiler error if you try to use it,
since it's not enabled. At least that's how gcc does it.

Jul 22 '05 #6
Rolf Magnus wrote:

Well, if you disable it, you'll get a compiler error if you try to use it,
since it's not enabled. At least that's how gcc does it.


Not with visual studio, you get a run-time exception. Real handy.
Jul 22 '05 #7
Victor Bazarov wrote:
If you can create two programs where one _uses_ RTTI and the other does
not, and otherwise they are _absolutely_ the same, then you can measure
the _real_ overhead. However, logically, that's impossible. If your code
does not use RTTI, why enable RTTI?


It's the other way round. If RTTI imposes no overhead, why bother disabling
it and risk potential problems with e.g. libraries your program uses?
If there is a significant difference, it might be worth finding out for each
target compiler and each used library if you can disable RTTI.

Jul 22 '05 #8
"Ioannis Vranos" <iv*@remove.this.grad.com> az alábbiakat írta a következo
hírüzenetben: 1104955152.262790@athnrd02...
Agoston Bejo wrote:

"Enabling" exceptions in nowadays implementations should incur no
overheads (unless an exception is thrown in which case what should be
considered as overhead is not clear).


To my best knowledge, this is not true. That is the main point. I read that
enabling exceptions gets the compiler to generate additional (additional
compared to exceptional-disabled code) code for implementing unwind
semantics, which does make the program run some 20-40% slower (I don't
remember the exact amount) even if not a single throw statement occurs in
your program. That's why you have the possibility to turn it off, I think.

Jul 22 '05 #9
Agoston Bejo wrote:
"Ioannis Vranos" <iv*@remove.this.grad.com> az alábbiakat írta a következo
"Enabling" exceptions in nowadays implementations should incur no
overheads (unless an exception is thrown in which case what should be
considered as overhead is not clear).

To my best knowledge, this is not true. That is the main point. I read that
enabling exceptions gets the compiler to generate additional (additional
compared to exceptional-disabled code) code for implementing unwind
semantics, which does make the program run some 20-40% slower (I don't
remember the exact amount) even if not a single throw statement occurs in
your program. That's why you have the possibility to turn it off, I think.


<musing>

I thought 'overhead' meant time( cycles ) and/or space ( bytes ). If
nothing else thermodynamics prevents something for nothing - information
( = energy ) included. Any 'throw' has to know where it's caught,
directly or otherwise, whatever else happens - stack unwinding,
destructors et al. It's a potential execution path 'to the side' of
one's code. No doubt compilers ( and their writers ) differ in skill as
applied to this. After all the Standard only requires 'as if' behaviour,
not performance per se ( to my knowledge ).

With a compiler enabled for exceptions, I'd be dissapointed with any
overhead if I'd never used catch, throw etc. Having said that, I might
well be implying it sometimes via #includes, libraries ... without
knowing it.

<end musing>

--

Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
Jul 22 '05 #10

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

Similar topics

9
by: Rick | last post by:
Hi, I wrote a few classes recently and am writing a small GC implementation for C++. I will be implementing my own gc_ptr type maintain a list where I'll store pointers to allocated memory. I...
2
by: shishir | last post by:
Please consider the following //file test.cpp #include <iostream> int main() { int x; try { throw x;
6
by: Kleidemos | last post by:
If I implement a simple RTTI system, more simple than C++ RTTI system for my program and this system is plus or minus: #define DEF_RTTI_BASE(name) virtual inline const char *Name(){ return...
2
by: denny | last post by:
Hey all, I know that dynamic_cast<> takes some time, but , for instance, is there a memoy cost associated in with it? Does it have to maintain a table in memory, thus bloating the runtime ram...
3
by: Steven T. Hatton | last post by:
I'm trying to work out a design for dynamically determining file types, and for generating new files of a given type. I'm curious to know what others think of my current strategy. Is it "so...
9
by: Vikram | last post by:
I was just curious to know how are calls like say dynamic_cast implemented. Is it really expensive to get the exact type of an object being pointed to by the baseclass pointer? The reason I am...
10
by: Neo | last post by:
what is RTTI? and how to implements it? give me sourceful link for learn and implements it (using standard C mean portable). regards, -aims
5
by: dotNeter | last post by:
I'm studying the RTTI, and my current work is concern for how to get the self-defined type at runtime, that's exactly what the RTTI does. I mean, in my application, I built several self-defined...
2
by: Chameleon | last post by:
I know than dynamic_cast check string name of derived to base class and if one of them match, return the pointer of that object or else zero. I suppose, I dynamic_cast instead of strings, checks...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.