473,387 Members | 3,781 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,387 software developers and data experts.

Performance using member of

If I have a class object and a pointer to the object is there a
performance hit for invoking a member function using member of (.) vs
member of (->) due to pointer arithmetic? From an amateur point of
view I'd initially think that the pointer arithmetic would cause a
slow down. On the other hand pointer arithmetic shouldn't even be an
issue since the member functions aren't actually part of the object
but instead a member of the class.

Please advise.

--
Thanks,
Lilith
Feb 11 '06 #1
3 1453
TB
Lilith sade:
If I have a class object and a pointer to the object is there a
performance hit for invoking a member function using member of (.) vs
member of (->) due to pointer arithmetic? From an amateur point of
view I'd initially think that the pointer arithmetic would cause a
slow down. On the other hand pointer arithmetic shouldn't even be an
issue since the member functions aren't actually part of the object
but instead a member of the class.

Please advise.


Slow down? Do you expect a noticable performance decay?
No difference of any vital concern. Don't bother
reflecting upon it.

--
TB @ SWEDEN
Feb 11 '06 #2

"Lilith" <li****@dcccd.edu> wrote in message
news:fu********************************@4ax.com...
If I have a class object and a pointer to the object is there a
performance hit for invoking a member function using member of (.) vs
member of (->) due to pointer arithmetic? From an amateur point of
view I'd initially think that the pointer arithmetic would cause a
slow down. On the other hand pointer arithmetic shouldn't even be an
issue since the member functions aren't actually part of the object
but instead a member of the class.


Write your code so as to be as simple and easily
readable as possible. Only worry about performance
if you can *prove* it's an issue (by measurement).

I strongly doubt you'll see a measurable difference
between using '.' operator vs '->' operator.

-Mike
Feb 11 '06 #3
On Sat, 11 Feb 2006 09:41:31 -0600, Lilith <li****@dcccd.edu> wrote:
If I have a class object and a pointer to the object is there a
performance hit for invoking a member function using member of (.) vs
member of (->) due to pointer arithmetic? From an amateur point of
view I'd initially think that the pointer arithmetic would cause a
slow down. On the other hand pointer arithmetic shouldn't even be an
issue since the member functions aren't actually part of the object
but instead a member of the class.

Please advise.


You are correct when you say that pointer arithmetic shouldn't be an
issue. The physical address of a particular non-static member function
should be the same whether one calls it on an object or on a pointer.
It should be actually the same for all objects of the same class ...
if anything, calling through a pointer (i.e. with -> syntax) is
conceivably faster than with the dot operator because each member
function gets passed a hidden argument: the "this" pointer of the
object involved. Since the pointer already contains that address, it
shouldn't have to be "looked up" or calculated with some kind of
pointer arithmetic.

But if you think about how the machine code generated by the compiler
would have to be seen by the CPU, ask yourself: What is an "object"?
According to most definitions of an object, it is an area of storage
with a certain structure as determined by the class declaration. But
any area of storage at that low level would have to be accessed
through memory addresses, IOW pointers. The only difference is that a
pointer occupies storage of its own, but every compiler is "smart
enough" to be able to optimize away that one level of indirection
under most circumstances.

--
Bob Hairgrove
No**********@Home.com
Feb 12 '06 #4

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

Similar topics

3
by: Roland | last post by:
Hi! I am working on a project in which i implement a mathematical optimization algorithm. One of the requirements on the code is very good performance. So i started to optimize a bit. Now i do...
10
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
1
by: foldface | last post by:
Hi Is there any difference between using this.member and member performancewise. I'm sure I could find out if I could read the decompiled stuff but I can't yet. In general is there any info out...
18
by: Rune B | last post by:
Hi Group I was considering using a Generic Dictionary<> as a value container inside my business objects, for the reason of keeping track of fields changed or added and so on. - But how...
1
by: jvn | last post by:
I am experiencing a particular problem with performance counters. I have created a set of classes, that uses System.Diagnostics.PerformanceCounter to increment custom performance counters (using...
13
by: atlaste | last post by:
Hi, I'm currently developing an application that uses a lot of computational power, disk access and memory caching (to be more exact: an information retrieval platform). In these kind of...
3
by: chsalvia | last post by:
In generic programming, static member functions and functors seem to be very useful. I've noticed that some libraries take the approach of using templated static member functions to provide...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.