473,799 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Virtual Function Performace: Say what Stan?

I stumbled upon this blog while googling for something. I have to say, I
really don't understand what Lippman is trying to tell me here. I included
the first paragraph for context, but the second paragraph is the one that
has me most confused.

<quote url="http://blogs.msdn.com/slippman/archive/2004/01/27/63473.aspx">
In C++, a programmer can suppress a virtual call in two ways: directly use
an object of the class, in which case the polymorphism of the object is
eliminated except in the trivial case in which the subtype hierarchy is the
same size as the class of the object being directly manipulated. [The
analogy under .NET, although it is not supported, would be toggling a
reference type into a value type for some small program extent, eliminating
the overhead of the managed heap and the virtual mechanism of the
interface.] Obviously, this is a very special use of the polymorphic
object, and is as likely to be an error on the programmer?s part as to be
his intention. However, the ability to design first class value types ?
think of them as Abstract Data Types ? and value type inheritance is
something that I sorely miss under .NET, where complex value types are in
my experience somewhat gimped. The second and more prevalent mechanism to
suppress a virtual call is to invoke a class method through the fully
qualified class scope operator. For example,

WidgetExtension ::display() { Widget::display (); /* now our
specialized display */ }
This pattern of localization within a call chain of a type-dependent method
relies on the ability of the user to limit the number of methods invoked to
the initial virtual instance, which can occur anywhere within the
inheritance chain. The subsequent chain of base class calls are then inline
expanded. Without explicit language support, the habit of programmers
concerned with performance [I don?t have any hard data, so this is
anecdotal] is to duplicate the base class code within the derived instance
to achieve the same result. This of course tightly couples the
implementation of the method with that of the base hierarchy and a single
change in the state members can cause the whole thing to derail. [The state
of OO optimization is not currently far enough along to guarantee the
elimination of these calls although that is, of course, feasible in
theory.]
</quote>

Doe anybody understand what he's trying to say? Can a relatively simple
example be created to show both the kind of class hierarchy he is talking
about, and what is meant by "suppress a virtual call is to invoke a class
method through the fully qualified class scope operator" (which I think I
vaguely understand), nd "The subsequent chain of base class
calls are then inline expanded"?

As I understand things, a virtual function invocation is a lookup in a vtbl
followed by an access to the actual function being executed. I guess he
could mean that a derived class would have its own vtbl pointing to its
baseclass, etc., and that the "chain of base class calls" is the process of
climbing up that vtbl stack.

--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #1
3 1641
Steven T. Hatton wrote:
[...]
As I understand things, a virtual function invocation is a lookup in a vtbl
followed by an access to the actual function being executed.
Only if the call is made through a variable declared as a pointer or
a reference. If the call is made for an _object_ directly, as in

MyPolymorphicCl ass anObject;
anObject.someVi rtualFunction() ; // no vtbl lookup occurs

or if the function is explicitly classified

MyPolymorphicCl ass anObject;
anObject.MyBase ::someVirtualFu nction(); // no vtbl lookup occurs

there is no lookup-and-redirection. The call is "statically " linked to
the appropriate function.
I guess he
could mean that a derived class would have its own vtbl pointing to its
baseclass, etc., and that the "chain of base class calls" is the process of
climbing up that vtbl stack.


I didn't see that. I am not sure why you think that.

V
Jul 23 '05 #2
Victor Bazarov wrote:
Steven T. Hatton wrote:
[...]
As I understand things, a virtual function invocation is a lookup in a
vtbl followed by an access to the actual function being executed.


Only if the call is made through a variable declared as a pointer or
a reference. If the call is made for an _object_ directly, as in

MyPolymorphicCl ass anObject;
anObject.someVi rtualFunction() ; // no vtbl lookup occurs

or if the function is explicitly classified

MyPolymorphicCl ass anObject;
anObject.MyBase ::someVirtualFu nction(); // no vtbl lookup occurs

there is no lookup-and-redirection. The call is "statically " linked to
the appropriate function.
> I guess he
could mean that a derived class would have its own vtbl pointing to its
baseclass, etc., and that the "chain of base class calls" is the process
of climbing up that vtbl stack.


I didn't see that. I am not sure why you think that.

V

I think I figured out what he mean. He was suggesting the chain of calls
was like this (going backwards):

class Base{
virtual void f() {
//do something
}
}

class Derived: public Base {
void f() {
Base::f();
// do more stuff
}
};

class DerivedDerived: public Derived {
void f() {
Derived::f();
// do more stuff
}
};
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #3
Steven T. Hatton wrote:
Victor Bazarov wrote:
Steven T. Hatton wrote:
[...]
could mean that a derived class would have its own vtbl pointing to its
baseclass, etc., and that the "chain of base class calls" is the process
of climbing up that vtbl stack.
I didn't see that. I am not sure why you think that.

V


I think I figured out what he mean. He was suggesting the chain of calls
was like this (going backwards):

class Base{


Most likely

public:
virtual void f() {
//do something
}
} ;
class Derived: public Base {
protected:

or

public:
void f() {
Base::f();
// do more stuff
}
};

class DerivedDerived: public Derived {
void f() {
Derived::f();
// do more stuff
}
};


OK, IOW nothing automatic is happening. You can provide the "chain" if
you use the scope resolution in your code, as you have shown here.

V
Jul 23 '05 #4

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

Similar topics

11
4370
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining it inline. Like this.
9
13061
by: kish_nand | last post by:
Could someone please explain me the concept behind virtual functions and vtables. I am little confused about this. Please refer to the following code and tell me how many virtual tables would be created and what they would contain: class base { virtual void display() { cout<<"base display"<<endl;
13
2368
by: dimitris67 | last post by:
How can I replace an occurence of p(a string) in an other string(s) with np(new string).. char* replace _pattern(char *s,char *p,char *np) PLEASE HELP ME!!!!!
2
1501
by: ilovecpp | last post by:
it's a little bit comlicated to me.
4
1528
by: Stan.Loughmiller | last post by:
I am trying to get a function to loop in C# while allowing the rest of the program to run. The function is a boolean that constantly checks the state of a switch while a program is run. If the switch is activated then the program is stopped and a new program is started. Is this possible in C#, if so, where do I start. Thanks, Stan
11
3457
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the vtable pointer is made use of.. eg. class one {
3
2822
by: Stan McCann | last post by:
I've searched and searched for a function to create an array from a string maintaining key/value pairs and keep coming up blank. This seems to me that it would be quite commonly used. What I am doing is trying to pass an array using $_GET. To pass the array, it is rather simple to add it to my get string breaking the array into key,value,key,value,key,value. The problem is reading it back into an array. I've tried explode but that...
10
4812
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a pure virtual function body
17
3552
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;" instead? I think declaring a function as "=0" is the same
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7571
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.