dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]Re: pnetlib architecture


From: Rhys Weatherley
Subject: Re: [DotGNU]Re: pnetlib architecture
Date: Wed, 06 Feb 2002 08:57:06 +1000

Tim Terlegård wrote:

> > Technically speaking, methods inside the VM are "internal
> > call" methods, and methods outside the are VM "platform
> > invoke" (or PInvoke) methods.
>
> PInvoke methods, are they C# class methods or do they belong to pnet?

PInvoke is a mechanism, defined by Microsoft and part
of the ECMA specifications, for calling pre-existing C
code from C# code.  The programmer inserts a prototype
for the C function into their C# code, together with any
extra marshalling information, and the engine takes care
of converting from the C# world to the C world.  e.g.
if I wanted to call the C puts routine, I would do something
like this:

[DllImport("libc.so")]
extern int puts(String str);

Once this declaration is in the C# code, it can be called
like any normal method and the system will thunk across
to libc and call puts.

Internal call methods are more like Java's native methods.
They are marked as internal, and the VM figures out how
to map the method to the underlying implementation through
means that aren't explicitly stated in the C# code.

Internal calls are better for low-level library tasks, because
they can be made system-independent.  PInvoke binds the
library to systems that have the specified library.  e.g. the
above "puts" wouldn't work on Windows because it doesn't
have a "libc.so".

> Something like this?

PInvoke essentially bypasses Pnet to go direct to the
OS or other system facilities.  But your diagram was
correct other than that.

> > Assuming that they don't deliberately build some Mono
> > VM dependency into their code, it should run on top of
> > some future version of pnetlib just fine, even though the
> > pnet VM has a different set of internal call methods.
>
> Is PInvoke standardised? I mean, does Mono also use PInvoke methods? If not,
> how could Mono run on top of pnetlib?

PInvoke is part of the ECMA standard.  There are some minor
extensions that are needed to support Unix platforms (it was
designed originally for Windows of course).  Both Mono and
pnet have roughly the same PInvoke extensions - they are
compatible enough for integration purposes.

Note: we aren't trying to run all of Mono on top of pnetlib.
Only certain libraries.  Because these libraries use PInvoke
or low-level functions that pnetlib will have, it should work.

> I'm thinking of contributing to pnetlib, but I'd like to be less confused
> first  :)

If you want to contribute to pnetlib, then you don't really
need to know much about high-level libraries of PInvoke.
Just follow the ECMA spec for the time being, and
everything else will fall into place in time.

Cheers,

Rhys.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]