473,569 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inline methods and pointers to members

Can the compiler ever inline a method when there is a pointer to the
member used?

Thanks,

--John Ratliff
Oct 11 '05 #1
8 1734
* John Ratliff:
Can the compiler ever inline a method when there is a pointer to the
member used?


Do you mean, "when there is a pointer to the method used", and by "method" you
mean non-static member function?

If so, yes, it can.

Or, depending on what you mean by "compiler", and how tied to 2005 technology
you want the answer, with e.g. MSVC it's the linker that does this job.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 11 '05 #2
John Ratliff wrote:
Can the compiler ever inline a method when there is a pointer to the
member used?


If the question is: does taking the address of a function (or a method)
prevent the compiler from inlining that function, the answer is "no".
Remember that function calls - not functions themselves - are inlined.
Whether the compiler decides to inline a particular function call has
no relation to other code that may take the address of the function
whose call is being inlined.

If the question is: can a function call through a function (or member)
pointer be inlined? The answer is "no" for any sensibly-written
program. To inline a function call through a pointer, the compiler
would have to be certain that the pointer would always point to the
same function on every call. And the compiler would have to be able to
deduce which function the pointer points to. But if the function
pointer never varies, why would the program bother with it and not just
call the pointed-to function directly? Use of a function pointer only
makes sense when the pointer has more than one function it could be
pointing to.

Greg

Oct 11 '05 #3
John Ratliff wrote:
Can the compiler ever inline a method when there is a pointer to the
member used?


If the question is: does taking the address of a function (or a method)
prevent the compiler from inlining that function, the answer is "no".
Remember that function calls - not functions themselves - are inlined.
Whether the compiler decides to inline a particular function call has
no relation to other code that may take the address of the function
whose call is being inlined.

If the question is: can a function call through a function (or member)
pointer be inlined? The answer is "no" for any sensibly-written
program. To inline a function call through a pointer, the compiler
would have to be certain that the pointer would always point to the
same function on every call. And the compiler would have to be able to
deduce which function the pointer points to. But if the function
pointer never varies, why would the program bother with it and not just
call the pointed-to function directly? Use of a function pointer only
makes sense when the pointer has more than one function it could be
pointing to.

Greg

Oct 11 '05 #4
Alf P. Steinbach wrote:
* John Ratliff:
Can the compiler ever inline a method when there is a pointer to the
member used?

Do you mean, "when there is a pointer to the method used", and by "method" you
mean non-static member function?

If so, yes, it can.

Or, depending on what you mean by "compiler", and how tied to 2005 technology
you want the answer, with e.g. MSVC it's the linker that does this job.


:-)

Thanks.

--John Ratliff
Oct 11 '05 #5
Greg wrote:
John Ratliff wrote:
Can the compiler ever inline a method when there is a pointer to the
member used?

If the question is: does taking the address of a function (or a method)
prevent the compiler from inlining that function, the answer is "no".
Remember that function calls - not functions themselves - are inlined.
Whether the compiler decides to inline a particular function call has
no relation to other code that may take the address of the function
whose call is being inlined.


This is what I was looking to understand. Thanks.

If the question is: can a function call through a function (or member)
pointer be inlined? The answer is "no" for any sensibly-written
program. To inline a function call through a pointer, the compiler
would have to be certain that the pointer would always point to the
same function on every call. And the compiler would have to be able to
deduce which function the pointer points to. But if the function
pointer never varies, why would the program bother with it and not just
call the pointed-to function directly? Use of a function pointer only
makes sense when the pointer has more than one function it could be
pointing to.


This was my problem. How could it inline a call through a pointer to member?

Thanks,

--John Ratliff
Oct 11 '05 #6

John Ratliff wrote:
Greg wrote:
John Ratliff wrote:
Can the compiler ever inline a method when there is a pointer to the
member used?

If the question is: does taking the address of a function (or a method)
prevent the compiler from inlining that function, the answer is "no".
Remember that function calls - not functions themselves - are inlined.
Whether the compiler decides to inline a particular function call has
no relation to other code that may take the address of the function
whose call is being inlined.


This is what I was looking to understand. Thanks.

If the question is: can a function call through a function (or member)
pointer be inlined? The answer is "no" for any sensibly-written
program. To inline a function call through a pointer, the compiler
would have to be certain that the pointer would always point to the
same function on every call. And the compiler would have to be able to
deduce which function the pointer points to. But if the function
pointer never varies, why would the program bother with it and not just
call the pointed-to function directly? Use of a function pointer only
makes sense when the pointer has more than one function it could be
pointing to.


This was my problem. How could it inline a call through a pointer to member?


I would first determine whether inlining the call through the member
pointer would really have a measurable effect on the program's
performance. In all likelihood, it would not. Performance problems that
can be solved with inlining alone are few and far between in my
experience.

Note also that if the method being called is virtual, the likelihood
that the compiler would inline even a direct call to the method are
also low. Inlining a call to a virtual function is possible only in
limited cases, when the type of object whose method is being invoked is
both known and unvarying.

Using a function object instead of a function pointer often provides
better inlining potential, since the type of the function object is
usually known at compile time. Replacing the member function pointer
with an enum that is used as a selector in a switch statement to
dispatch the function call would be another way to make the call more
suitable for inlining.

Greg

Oct 11 '05 #7
>>>If the question is: can a function call through a function (or member)
pointer be inlined? The answer is "no" for any sensibly-written
program. To inline a function call through a pointer, the compiler
would have to be certain that the pointer would always point to the
same function on every call. And the compiler would have to be able to
deduce which function the pointer points to. But if the function
pointer never varies, why would the program bother with it and not just
call the pointed-to function directly? Use of a function pointer only
makes sense when the pointer has more than one function it could be
pointing to.
This was my problem. How could it inline a call through a pointer to member?

I would first determine whether inlining the call through the member
pointer would really have a measurable effect on the program's
performance. In all likelihood, it would not. Performance problems that
can be solved with inlining alone are few and far between in my
experience.


I doubt any of my inlined methods produce any measurable performance
impact, but when you are searching for one line methods in a file where
every other method is significanly longer, it's easier to find them in
the header file. This is why I declare them inline. I used to put all my
one line methods the class declaration, but after I read the C++ FAQ, I
stopped doing that. A good IDE would probably be just as good of a
solution, but until I find one, jEdit works fine for me.

I rarely enhance my code to increase performance. It's never been
necessary for me in any language but Java. I used to optimize for space
when I wrote C programs for calculators, but that was only because
user-space memory was only 262K.

Then I started wondering how it was going to inline the call through the
pointer to member for all my one line event handlers (callbacks, slots,
insert synonym here). It's probably never going to do that, but since
I'm not really interested in the inlining, only the question of the
possibility, the result doesn't really matter.

Note also that if the method being called is virtual, the likelihood
that the compiler would inline even a direct call to the method are
also low. Inlining a call to a virtual function is possible only in
limited cases, when the type of object whose method is being invoked is
both known and unvarying.
None of my questioned methods are virtual. The way event handling works
in wxWidgets, they can't be.

Using a function object instead of a function pointer often provides
better inlining potential, since the type of the function object is
usually known at compile time. Replacing the member function pointer
with an enum that is used as a selector in a switch statement to
dispatch the function call would be another way to make the call more
suitable for inlining.


Thanks,

--John Ratliff
Oct 11 '05 #8
> it's easier to find them in the header file.
...
A good IDE would probably be just as good of a solution,
but until I find one....


The Zeus for Windows IDE uses ctags for it's source of tags
information and it stores this information in special tag
database files:

http://www.zeusedit.com/forum/viewtopic.php?t=185

These database files are used to drive the class browsing,
intellisensing and tag searching features.

In particular the tag searching option makes it very easy
to quickly locate functions, variables and classes.

Jussi Jumppanen
Author: Zeus for Windows IDE
Note: Zeus is shareware (45 day trial).

Oct 28 '05 #9

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

Similar topics

2
10098
by: Jeff Williams | last post by:
The common method of defining template classes and functions is to put the definition and declaration into the same header file. Or at least I believe it to be the common method and it is certainly the one I use. This leaves me with a question. As example, consider the following class. template<class T> class foo
13
6540
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg. accessor and mutator methods to access private data members). I would like to know if there are any issues with using inline functions that may have...
7
2025
by: Alvin | last post by:
Hello all, I'm curious as to your opinions on explicitly inlining function? I'm talking about functions as members of a class. For example, so class A defines a operator==() and a operator!=(): class_a.h: class A {
30
19687
by: Will Pittenger | last post by:
Does C# inline functions? I do not see a inline keyword. Is there an implicit inline? Can the compiler select functions for auto-inlining? I am more used to C++ where all these things are possible. ---------- Will Pittenger E-Mail: mailto:will.pittenger@verizon.net All mail filtered by Qurb (www.qurb.com)
5
14015
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources......
25
12999
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void *p, void *q) that will take any two pointers and decide whether they can be compared or not. I really can't think how to do this - any...
12
1731
by: subramanian100in | last post by:
Can a ctor be declared inline ? Is it not declared inline to avoid executable code size becoming huge ? kindly clarify Thanks V.Subramanian
22
1649
by: Ruben | last post by:
Why would a method that is defined to return a reference such as with the operator overload of , operator, href& operator(int index){ return _array; } not cause a type mismatch compiler error? Ruben
17
8360
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline the function if possible" (because if the compiler has the function definition available at an instantiation point, it will estimate whether to...
0
7694
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...
0
7609
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...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
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
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.