473,471 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

out method and method with return value

In performance wise which is more costly to use when there one value to return?
Is it the out method parameter or the method that has a return value?

Dec 19 '07 #1
10 1336
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?
Return value I presume. In most languages the return value is returned in a
register whereas a parameter is placed on the stack.
>

Dec 19 '07 #2
lianqtlit wrote:
In performance wise which is more costly to use when there one value to return?
Is it the out method parameter or the method that has a return value?
It is extremely unlikely that the difference will have any impact on
your overall performance.

Focus on readable code instead of "nanoseconds performance tuning".

Arne
Dec 19 '07 #3
Michael C wrote:
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
>In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?

Return value I presume. In most languages the return value is returned in a
register whereas a parameter is placed on the stack.
Did you read it as "more efficient" or do you think register is slower
than stack ?

Arne
Dec 19 '07 #4
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:47***********************@news.sunsite.dk...
Did you read it as "more efficient" or do you think register is slower
than stack ?
Sorry, I misread what the OP said. I think the register will be faster and
more efficient.

Michael
Dec 19 '07 #5
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?

You should definitely not care about this, chances are that the method is
inlined, and if not, the (single) argument is passed in a register too.
Managed code uses the "CLR calling" convention when running on X86, that is,
it passes the first two arguments in a register. The 'this' pointer is
passed in 'ecx' while the "first" argument is passed in 'esi'. More, when
running on X64 in 64-bit mode, the first four arguments are passed in a
register, so here you have even less reasons to care about argument passing
efficiency.

Willy.
Dec 19 '07 #6

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
>In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?


You should definitely not care about this, chances are that the method is
inlined, and if not, the (single) argument is passed in a register too.
out arguments have to be passed by address... unless inlined

Just make sure the function is inlined.

As a side note, the out parameter can use type inference, the return type
can't (except for op_Implicit and op_Explicit).
Dec 19 '07 #7
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:uW**************@TK2MSFTNGP04.phx.gbl...
>
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
>"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microso ft.com...
>>In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?


You should definitely not care about this, chances are that the method is
inlined, and if not, the (single) argument is passed in a register too.

out arguments have to be passed by address... unless inlined
Yep, sorry for the confusion, what I meant was that a single argument is
passed in a register, not on the stack.
What is returned is also placed in a register (by convention eax on X86), be
it an address or a value
Just make sure the function is inlined.
You don't have control over this, it's the JIT who decides what will be
inlined.
As a side note, the out parameter can use type inference, the return type
can't (except for op_Implicit and op_Explicit).
Agreed.

Willy.


Dec 20 '07 #8
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
You should definitely not care about this, chances are
Chances are much improved (to certainty) that the return value will be in a
register if it is not a parameter. :-)

Michael
Dec 20 '07 #9
"Michael C" <mi**@nospam.comwrote in message
news:u$**************@TK2MSFTNGP04.phx.gbl...
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
>You should definitely not care about this, chances are

Chances are much improved (to certainty) that the return value will be in
a register if it is not a parameter. :-)

Michael
Sure, on X86 return values can even occupy two registers, a long or a double
return value for instance are returned in 'eax' and 'edx'. Note that I'm
absolutely not promoting passing ByRef values, this is a matter of the
semantic requirements, all I'm trying to say is that the JIT32 uses a
calling sequence which allows you to pass single argument (plus the this
pointer) in a register.

Willy.


Dec 20 '07 #10
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:ei**************@TK2MSFTNGP06.phx.gbl...
Sure, on X86 return values can even occupy two registers, a long or a
double return value for instance are returned in 'eax' and 'edx'. Note
that I'm absolutely not promoting passing ByRef values, this is a matter
of the semantic requirements, all I'm trying to say is that the JIT32 uses
a calling sequence which allows you to pass single argument (plus the this
pointer) in a register.
Interesting, that's something I didn't know. I still think though that if
you want performance you'd be better off going with the return value because
then you can be pretty much certain it will return in a register. It's
possible in the future your code might not be running on x86.

Michael
Dec 20 '07 #11

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

Similar topics

6
by: max reason | last post by:
A method in one of my classes needs to call one of 256 other methods in the same class based on an unsigned 8-bit value (0x00 to 0xFF). How is this done? Everything I try generates errors. ...
1
by: =steFF= | last post by:
Hi, I am trying to print the values I have in a vector and my compiler says: error C2227: left of '->printLn' must point to class/struct/union on this instruction: m_data->printLn(); (in my file...
12
by: Rubbrecht Philippe | last post by:
Hi there, According to documentation I read the ArrayList.IndexOf method uses the Object.Equals method to loop through the items in its list and locate the first index of an item that returns...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
1
by: tony | last post by:
Hello!! Hello Victor! I use a product called flygrid to create grid tables. In many of my forms I create such grid tables. Some columns in these grid tables is of type drop down list where I...
3
by: BombDrop | last post by:
Can any one help I have a method that will return a List to be bound as a datasource to a combobox see code for population below. I get the following error when i try to compile Error 29 ...
0
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the...
5
by: Anders Borum | last post by:
Hi! While implementing a property manager (that supports key / value pairs), I was wondering how to constrain T to a struct or string type. Basically, I guess what I'm looking for is the common...
1
by: madman228 | last post by:
Hi guys I have run in to a littl bit of trouble. I am writing a class called polynomial in which i need a derivative method I have everything, just dont know how to start the derivative method. Any...
0
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...
0
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,...
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
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,...
1
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...
0
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...
0
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 ...

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.