[Mono-list] Jon's reply : Parameter passing using PInvoke

Shankari shankari82 at yahoo.com
Wed Oct 19 20:15:32 EDT 2005

here is Jon's answer to my queries. Any more insights
or clarifications are welcome.

>   : I have a structure in my C# code. If
> in my invocation, I pass a reference to this
> structure.  I want to know the size of the struct in
> mono. I guess it pushes the "address" on to the
> But I want the size of the struct pointed to by the
> address.
> Is there any way to get this.

System.Runtime.InteropServices.Marshal.SizeOf(). :-)

Though there's an important question: is this through
P/Invoke or
through an icall interface?  And is it a C# struct or
a C# class?

For P/Invoke it doesn't matter, but for icalls the
class will have the
standard object header, which is 8 bytes in size IIRC.

> mono_marshal_type_size doesnt seem to be the right
> function..

Why not?

> I dereferenced the pointer at the
> level  as *(sig->params[i])->data.klass and the
> instance size is shown as 24. where as my structre
> just has 4 in values i.e 16.

Either your structure has padding issues, or you're
within an icall
interface passing a reference type, thus you'd have
the object header 
contend with.

> If I need to copy this structure by value ...what
> should I be using = 16 or instance size of 24??
> If it is 16 : How can we get this in *mono* (not at
> the C# program level).

I lack the knowledge to answer this.

 - Jon

Yahoo! Music Unlimited 
Access over 1 million songs. Try it free.

More information about the Mono-list mailing list