X
X
Xlab2012-07-24 22:14:06
OOP
Xlab, 2012-07-24 22:14:06

What is the best way to pass objects to a function - by reference or by value?

Good evening.
Recently, the thought came to me why structures are more effective than objects, because it is much easier to pass a reference to an object than to copy. I used to blame everything on the initialization of the object itself, but recently I saw a few comments that passing by value (cheap copying) is optimal in principle.
Tell me, where can I find a good explanation or, even better, a good set of benchmarks?
I myself do not have enough experience to write test cases.
UPD.
I asked the question crookedly and incorrectly.
stackoverflow.com/questions/270408/is-it-better-in...
stackoverflow.com/questions/2139224/how-to-pass-ob...
The links are correct questions and correct answers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gouranga, 2012-07-25
@Xlab

Actually, marklarius 's answer does show when it's okay to use structs in .NET .

Well, again small objects. Thank you, but there is not enough information yet.

And this is just one of the most important factors for using structures. Only for small objects with which you are not going to box often. And, of course, only for objects with a short life cycle.

M
marklarius, 2012-07-24
@marklarius

nprogramming.wordpress.com/2010/06/01/c-performance-class-vs-struct/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question