get() function vs public member

P

Philipp

Hello
I profiled my program and got as result that two functions taking each
10% of the calculation time are simple get() for a member of a class
(returning a pointer).

Do you think that generally accessing this member directly (making it
public) would speed up things vs using the get function as an interface?

(if you thinks this might be compiler related, I'm using the following
gcc 3.3.1 (used for profiling with gprof on win2k)
icc 7.1 (for production, on linux)
Metrowerks Code Warrior C++ compiler 3.0.3 (for developping on win2k)

Thanks for your answers
Philipp
 
M

Marcin Kalicinski

Hello
I profiled my program and got as result that two functions taking each
10% of the calculation time are simple get() for a member of a class
(returning a pointer).

Do you think that generally accessing this member directly (making it
public) would speed up things vs using the get function as an interface?

At least on MSVC 7.0 or newer, with properly configured optimization there
should be completely no performance hit, even in the get() functions are
defined in different module than they are used from.

Marcin
 
K

Karl Heinz Buchegger

Philipp said:
Hello
I profiled my program and got as result that two functions taking each
10% of the calculation time are simple get() for a member of a class
(returning a pointer).

Do you think that generally accessing this member directly (making it
public) would speed up things vs using the get function as an interface?

Did you make the getter an inline function?
If so and the compiler inlined that function (very likely), there
should be absolutely no performance difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top