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

inlining function objects

Hi.

I'm just curious if there any warnings or caveats or whatever to be
aware of when inlining function object calls? If the answer is no, they
inline just like everything else, that's good news for me.

glen
Jul 22 '05 #1
6 1602
glen_stark wrote:
Hi.

I'm just curious if there any warnings or caveats or whatever to be
aware of when inlining function object calls? If the answer is no, they
inline just like everything else, that's good news for me.


I suspect you mean "member function" in the place of "function object
calls".

This is an implementation detail. You'll need to check your specific
compiler.

Having said that, most (if not all) implementations don't have any
constraints in this area that I have seen.

Jul 22 '05 #2
glen_stark wrote:
Hi.

I'm just curious if there any warnings or caveats or whatever to be
aware of when inlining function object calls? If the answer is no,
they inline just like everything else, that's good news for me.


Actually, one reason to use function objects is because can be inlined
in some situations where normal functions can't.

Jul 22 '05 #3

"Rolf Magnus" <ra******@t-online.de> wrote in message
news:c1*************@news.t-online.com...
glen_stark wrote:
Hi.

I'm just curious if there any warnings or caveats or whatever to be
aware of when inlining function object calls? If the answer is no,
they inline just like everything else, that's good news for me.


Actually, one reason to use function objects is because can be inlined
in some situations where normal functions can't.


Could you show a specific example please?

-Mike
Jul 22 '05 #4
On Tue, 24 Feb 2004 01:40:40 GMT in comp.lang.c++, "Mike Wahler"
<mk******@mkwahler.net> was alleged to have written:
Actually, one reason to use function objects is because can be inlined
in some situations where normal functions can't.


Could you show a specific example please?


template <typename F>
void callfun(F *f)
{
(*f)();
}

Now, if you pass a function to this, the function to be called is (*f)
and only by dereferencing the pointer passed can the generated code call
the function.

But, if you pass a functional object the function to be called is
sometype::operator() regardless of the pointer value, and the call can
probably be inlined.
Jul 22 '05 #5


David Harmon wrote:
Actually, one reason to use function objects is because can be inlined
in some situations where normal functions can't.


Could you show a specific example please?


template <typename F>
void callfun(F *f)
{
(*f)();
}

Now, if you pass a function to this, the function to be called is (*f)
and only by dereferencing the pointer passed can the generated code call
the function.

But, if you pass a functional object the function to be called is
sometype::operator() regardless of the pointer value, and the call can
probably be inlined.
...


This is not a fair comparison. The above version of the code is run-time
parametrized and the call cannot be resolved at compile time (which
prevents inlining). The functional object version is compile-time
parametrized, which makes inlining possible.

Run-time parametrization can be implemented with both ordinary functions
and functional objects (through virtual functions). In both cases
inlining is impossible.

Compile-time parametrization can also be implemented with both ordinary
functions and functional objects. In both cases inlining is possible.

Both run-time and compile-time parametrization has its own uses and its
own advantages/disadvantages.

In order to make fair comparison in our case, you have to make "ordinary
function" version compile-time parametrized. For example, like this

template <char (*F)(int)> char callfun(int i)
{
return F(i);
}

Function call can be inlined in this case.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #6
Andrey Tarasevich wrote:
David Harmon wrote:
Actually, one reason to use function objects is because can be
inlined in some situations where normal functions can't.

Could you show a specific example please?
template <typename F>
void callfun(F *f)
{
(*f)();
}

Now, if you pass a function to this, the function to be called is
(*f) and only by dereferencing the pointer passed can the generated
code call the function.

But, if you pass a functional object the function to be called is
sometype::operator() regardless of the pointer value, and the call
can probably be inlined.
...


This is not a fair comparison. The above version of the code is
run-time parametrized and the call cannot be resolved at compile time
(which prevents inlining). The functional object version is
compile-time parametrized, which makes inlining possible.


Right. But often, you don't actually need the run-time parametrization,
but still are forced to pay the penalty. Think of std::sort with a
custom comparison function.
Run-time parametrization can be implemented with both ordinary
functions and functional objects (through virtual functions). In both
cases inlining is impossible.
Right.
Compile-time parametrization can also be implemented with both
ordinary functions and functional objects. In both cases inlining is
possible.
Both run-time and compile-time parametrization has its own uses and
its own advantages/disadvantages.

In order to make fair comparison in our case, you have to make
"ordinary function" version compile-time parametrized. For example,
like this

template <char (*F)(int)> char callfun(int i)
{
return F(i);
}

Function call can be inlined in this case.


Hm, do any compilers actually do that? Anyway, none of the standard
library algorithms are using this, so you either have to use funciton
objects or go without inlining.
Jul 22 '05 #7

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

Similar topics

17
by: Tony Vitonis | last post by:
From what I can tell, VB.NET doesn't allow programmers to say explicitly that they want a function to be inlined. Now, I'm a big fan of factoring out duplicate code, but I don't want to do too...
10
by: gianguz | last post by:
The question is about the possible use of inlining to improve performance in a heavy multithreading environment (200+ threads). If we have to work with applications in which threads aren't I/O...
8
by: Mat Booth | last post by:
If I call an inline member function through a member function pointer, will that function be inlined? I imagine it wouldn't because the function that's pointed to isn't known until run-time, is...
11
by: Elpoca | last post by:
Hi: What rules govern the inlining of templated functions and templated class methods? It has always been my understanding that both templated functions and templated class methods were...
15
by: Lloyd Dupont | last post by:
I have some code which looks like that: public CornerStyle RectCornerMode { get { return this.GetValue<CornerStyle>(); } set { this.SetValue<CornerStyle>(value); } }
21
by: Michael Hull | last post by:
Hi, I remember from somewhere reading that inlining constructors is a 'BadThing', but now can't seem to find the original source. I can't however thing of a reason why it would be for simple...
8
by: Yakov | last post by:
I'd like a tool that performed inlining of function bodies of which do not appear in the .h file. Really. gcc on Linux. Yakov
5
by: copx | last post by:
Do compilers inline functions even if the programmer could not do it manually because the needed information is hidden at the language level? I am talking about stuff like incomplete types and...
58
by: sh.vipin | last post by:
is there any way to find out number of bytes freed on a particular free() call in C
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.