Re: passing class to a function in c++ - performance question
From: Gianni Mariani (gi2nospam_at_mariani.ws)
Date: 03/30/05
- Next message: Pascal Obry: "Re: Class hierarchy of exceptions (Ada, C++)"
- Previous message: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- In reply to: Profil1: "passing class to a function in c++ - performance question"
- Next in thread: lilburne: "Re: passing class to a function in c++ - performance question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 30 Mar 2005 03:54:45 -0800
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
In practice, usually, passing by pointer vs by reference has the same
performance. However, since a reference cannot be changed once it is
seated, in theory, the optimizer may be more agressive with code
optimizations with references vs optimizations with pointers. So,
passing by reference may yield better optimized code (in theory).
The only real way to find out is to try it.
This also applies to the "register" keyword. The register keyword was
usually a hint to the compiler to allocate a register. An optimizer can
now read that it can't be aliased and hence it can perform better
optimizations. Again, this is theory only, what your compiler does is
the only thing that matters.
- Next message: Pascal Obry: "Re: Class hierarchy of exceptions (Ada, C++)"
- Previous message: Tapio Kelloniemi: "Re: Class hierarchy of exceptions (Ada, C++)"
- In reply to: Profil1: "passing class to a function in c++ - performance question"
- Next in thread: lilburne: "Re: passing class to a function in c++ - performance question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|