Re: passing class to a function in c++ - performance question

From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 03/30/05


Date: Wed, 30 Mar 2005 13:09:45 +0200

Profil1 wrote:
>
> Hi,
> I'm writing a code that has to be as efficient as possible both in terms of
> memory use and execution speed. I'll have to pass a class instance (which is
> an 'intelligent' array) to a function (multiple times). Taking this into
> consideration, should I pass it as a pointer or reference? Is there any book
> or site that teaches stuff like this (optimizing code for performance)?
> thanks for any help

There is only one way to figure out: Time it.

But usually both methods (pass by pointer, pass per reference)
have equal performance. This is so, because the compiler implements
'pass per reference' by passing a pointer under the hood. So in
the end it turns out, that you do the very same thing with different
syntax.

-- 
Karl Heinz Buchegger
kbuchegg@gascad.at


Relevant Pages

  • Re: How java passes object references?
    ... to think of them as being a specific location in a larger block of memory ... Whether a language passes by reference or by value, ... is a pointer pointing at the memory block. ... So when allocating local memory for o, it would simply allocate a ...
    (comp.lang.java.programmer)
  • Re: Lock-free reference counting
    ... Incrementing and decrementing scattered memory locations is the ... main reason reference counting is so slow. ... large blocks of such adjustments per page, ... to contain any long-lived pointer loops, ...
    (comp.programming)
  • Re: in defense of GC (was Re: How come Ada isnt more popular?)
    ... You can still have memory leaks ... pointer that still refers to allocated memory, ... Instead one simply clears the reference to the root of entire complex ...
    (comp.lang.ada)
  • Reference vs Pointer redux
    ... the distinction between a reference and a pointer. ... I pass parameters to a function by reference when I need to have the ... it's actually the memory address of the variable that is passed. ... I know that a pointer is a type of variable in C++ that holds the ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Reference vs Pointer redux
    ... > the distinction between a reference and a pointer. ... > it's actually the memory address of the variable that is passed. ... > pointer to an int holds the memory address of an int. ...
    (alt.comp.lang.learn.c-cpp)