473,699 Members | 3,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Will this be hard/expensive to inline?

I don't really understand the details of what happens when a compiler
inlines a given function. I know that basically it's supposed to cause the
function to be placed directly on the stack per invocation (or something
like that.) That would be in contrast to loading one instance of the
function and branching to it each time.

I don't believe that means I would have a separate instance of a member
function loaded per object instance. But I would like some verification in
this regard.

I'm wondering what the consequences of having the default case throw the
exception indicated in the following code:

template <typename T>
inline T Vector3<T>::ope rator[](const unsigned& index) const
throw (out_of_range)
{
switch(index){
case 0: return _v[0];
case 1: return _v[1];
case 2: return _v[2];
default:
std::stringstre am ss;
ss << namespace_name + "::"
<< class_name
<< "::operator[" << index <<"]";
throw out_of_range(ss .str());
}
}

Could that impact the ability of the compiler to inline the function, or
cause significant bloat if it were inlined?

I also wonder about the performance hit I take by using the switch
statement. I believe this boils down the fact that I can't both have my
cake (ideal performance) and eat it(checked access.) Is this really a case
of either/or? Could I reasonably expect a compiler to optimize away the
comparison for index values 0,1,2?
--
"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 22 '05 #1
2 1240
Steven T. Hatton wrote:
I don't really understand the details of what happens when a compiler
inlines a given function.

It's implementation dependant.

....
I'm wondering what the consequences of having the default case throw the
exception indicated in the following code:

template <typename T>
inline T Vector3<T>::ope rator[](const unsigned& index) const
throw (out_of_range)
{
switch(index){
case 0: return _v[0];
case 1: return _v[1];
case 2: return _v[2];
default:
std::stringstre am ss;
ss << namespace_name + "::"
<< class_name
<< "::operator[" << index <<"]";
throw out_of_range(ss .str());
}
}
This would probably be better:

template <typename T>
inline T & Vector3<T>::ope rator[](const unsigned& index)
{
if ( index > 2 ) // index is unsigned so it can't be less than 0
{
IsBadIndex( class_name, index );
assert( false ); // should never get here
}
return _v[ index ];
}

template <typename T>
inline const T & Vector3<T>::ope rator[](const unsigned& index) const
{
if ( index > 2 ) // index is unsigned so it can't be less than 0
{
IsBadIndex( class_name, index );
assert( false ); // should never get here
}
return _v[ index ];
}

And don't inline IsBadIndex ...

Could that impact the ability of the compiler to inline the function, or
cause significant bloat if it were inlined?

I also wonder about the performance hit I take by using the switch
statement. I believe this boils down the fact that I can't both have my
cake (ideal performance) and eat it(checked access.) Is this really a case
of either/or? Could I reasonably expect a compiler to optimize away the
comparison for index values 0,1,2?


My experience with optimizers is that they do a good job with conditionals.
Jul 22 '05 #2
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:1L******** ************@sp eakeasy.net...
I don't really understand the details of what happens when a compiler
inlines a given function. I know that basically it's supposed to cause the function to be placed directly on the stack per invocation (or something
like that.) That would be in contrast to loading one instance of the
function and branching to it each time.

I don't believe that means I would have a separate instance of a member
function loaded per object instance. But I would like some verification in this regard.
The keyword "inline" expresses the programmer's desire to have the
function's body inserted into the caller's body, eliminating the overhead
that can be associated with a function call. It has little to do with the
number of instances of an object. If some functions call a function X total
times, and that called function is inlined in every caller, then you would
have X copies of that function.
I'm wondering what the consequences of having the default case throw the
exception indicated in the following code:

template <typename T>
inline T Vector3<T>::ope rator[](const unsigned& index) const
throw (out_of_range)
{
switch(index){
case 0: return _v[0];
case 1: return _v[1];
case 2: return _v[2];
default:
std::stringstre am ss;
ss << namespace_name + "::"
<< class_name
<< "::operator[" << index <<"]";
throw out_of_range(ss .str());
}
}

Could that impact the ability of the compiler to inline the function, or
cause significant bloat if it were inlined?

<snip>

Well, as it has already been said, this is all depends on the
implementation. But I think it's worth noting that you are using an
exception specification, which is something that most experts do not
recommend you do. Sutter says that you shouldn't bother to write them
(http://www.gotw.ca/gotw/082.htm). The boost "exception specification
rationale" (http://www.boost.org/more/lib_guide....-specification)
mentions that some compilers turn off inlining if there is an exception
specification.

--
David Hilsee
Jul 22 '05 #3

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

Similar topics

46
7029
by: DJ WIce | last post by:
Hi all, I did make a script/css thing to replace the contextmenu on the website with a new one: http://www.djwice.com/contextmenu.html It works nice in MSIE, but on Netscape (and probable other browsers) it stays on the same place (does not "open'' where the mouse is). And the links do not work when you click on them. If anyone has sugestions on how to improve it, please let me know.
20
3138
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with extern linkage is inlined? Should the compiler still export the function? Or is an inlined function implicitly static?
8
3639
by: Gabor | last post by:
Hi, I have an app. that uses an MSDE database. I hardcoded the login and password in the application, but it is very simple to see with an ILDASM.exe tool. Is it any procedure to obscure the hard coded connection string, or how can I connect to the database with an encrypted password? Thanks in advance
4
2026
by: NotGiven | last post by:
setting up LAMP server. on old server with single Intel PII 450 MGHz, 64 MG Ram and two 9.1 GB Hard drives. How much RAM do I need to run MySQL efficiently?
16
9957
by: Blue Apricot | last post by:
X-No-Archive How long will Classic ASP be supported by Microsoft? Should I start learning ASP.NET? Is it hard if you already know ASP? Blue Apricot
3
6453
by: ary | last post by:
I try to create a weblog host site! in this case i can't use cache for every page because that cause to be my Server ram full of caching page. but if I can save cache in hard disk my problem solved? can help me? thanks.
3
6303
by: trahul87 | last post by:
Hi, I have a Toshiba Satellite A25 - S207. The internal hard disk has just crashed. I do not want to change the hard disk since its very expensive. So, is it possible to boot using an external hard disk connected through USB? Please help , i am in a real messy situation.
5
20030
by: Summercool | last post by:
wow... i didn't know that, for <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <span style="width: 100px; background: yellow">a</span>b <div style="width: 100px; background: yellow">a</div>b
3
3670
by: Kurt Mueller | last post by:
David, Am 07.10.2008 um 01:25 schrieb Blubaugh, David A.: As others mentioned before, python is not the right tool for "HARD REAL TIME". But: Maybe you can isolate the part of your application that needs
0
8623
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
9187
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9053
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...
0
8894
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6540
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
5879
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
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
3071
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
2360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.