[Mono-devel-list] calli opcode

Kornél Pál kornelpal at hotmail.com
Fri Jul 22 09:48:49 EDT 2005


> From: Jonathan Pryor
> On Thu, 2005-07-21 at 22:26 -0600, Peter Dennis Bartok wrote:
>> Jonathan, if you read through the DnD OLE code in the MWF win32 driver,
>> you
>> will see that I'm doing exactly that.
>
> This works because you're invoking a COM method, which has a
> well-defined ABI (stdcall calling convention, all arguments passed on
> the stack and NOT in registers, etc.).

Note that as well that Peter is using IntPtr's as the data type of all the
parameters. I think that you can use P/Invoke marshaling attributes in calli
signature when marshaling complex types but it will require much more work
to generate an calli using reflection with attributes. And of course C#
cannot emit calli so you have to use reflection. And I'm not sure that this
extra work is worth for the overall performance improvement. calli has to be
emitted then JIT-ed so I think you will feel the difference only when
calling these methods very frequently.

The other alternative is to use delegates but note that the main problem is
the same (as explained by Jonathan Pryor) both for calli and delegates that
you have to use very strict rules when defining object interfaces and if you
want the managed code to be platform independent the rules regarding the
vtable has to even more strict.

A reasonable solution could be implementing COM interface marshaling (CCWs
and RCWs) in the runtime because it could provide an easy way in managed
code and a well defined unmanaged interface design.

> This will NOT work for any arbitrary C++ method because each compiler
> has a different calling convention (register usage, parameter order on
> the stack, how to deal with exceptions).

COM has HRESULTs intead of exceptions that is a good practice because you
don't have to care about exceptions.

Kornél




More information about the Mono-devel-list mailing list