Re: Choosing function parameter types - pointers or objects?



ballpointpenthief posted:


I know this question is a bit vague, but I was wondering about any
rules / guidelines / style issues, for when to use pointers, and when
not to, in your function parameters?


You'd have the measure the efficiency of:

(1) Passing the object by value (thus copying it in the process).

and

(2) Passing its address, and dereferencing the address.


For the intrinsic types, (1) is faster.

For a huge type, an object of which is perhaps a kilobyte, (2) would be
faster.


I'm sure the others can give you a more detailed reply.

--

Frederick Gotham
.



Relevant Pages

  • Re: Choosing function parameter types - pointers or objects?
    ... Passing the object by value (thus copying it in the process). ... For the intrinsic types, is faster. ... The cut-off point between pass by value and by pointer varies form ...
    (comp.lang.c)
  • Re: textbook authors: passing by ref is NOT more efficient!
    ... efficiency in terms of performance and we are talking reference objects. ... passing by reference, as I am not allocating memory in many cases. ...
    (microsoft.public.dotnet.languages.csharp)
  • Efficient Parameter passing
    ... This is a general question to do with efficiency of passing parameters ... betwen functions. ...
    (microsoft.public.vc.mfc)
  • Re: Efficient Parameter passing
    ... > This is a general question to do with efficiency of passing parameters ... > betwen functions. ... > structure that holds the vectors and then passing a pointer to this structure ... passing a reference costs exactly the same as passing a pointer. ...
    (microsoft.public.vc.mfc)