If you are passing an interface or an instance of a class as a parameter, are we passing many objects or the full vtable, because once you call a method on the instance it need to recurse the vtable and call the appropriate one right?
How does this work?
views:
375answers:
3
+1
A:
You're ultimately passing a pointer to the object, which contains a pointer to the vtable. Well, basically.
OregonGhost
2009-03-05 15:09:45
A:
This is an implementation detail, so I think you shouldn't rely on that !:)
btw, there's no such thing as "passing an interface in parameter". You always pass an object reference which can implement none, one or several interfaces.
Brann
2009-03-05 15:10:09
Watch out for some post on Raymond Chen's blog in a few years, because he'll write about some old application that did rely on that!
OregonGhost
2009-03-05 15:11:58
@OregonGhost :ahah, very true !
Brann
2009-03-05 15:12:35
+5
A:
You're passing a reference (by value). The exact representation of a reference is implementation-specific, but in most cases it will be a pointer :)
See http://yoda.arachsys.com/csharp/parameters.html for more details.
(I'm on a phone at the moment - if someone could reformat the link that would be helpful :)
Jon Skeet
2009-03-05 15:19:44