[Mono-list] Hang on JIT-ing fn with P/Invoke?

Jonathan Pryor jonpryor at vt.edu
Fri Aug 10 10:39:48 EDT 2007

On Fri, 2007-08-10 at 15:03 +0100, Andy Hume wrote:
> Three quick questions if you happen to know the answers:
> 1. Is UnixMarshal.AllocHeap required rather than a call to
> Marshal.AllocHGlobal?

Yes.  You need a malloc(3) call, because that's what sdp_list_append()
seems to expect (though I may be mis-reading the source).
Marshal.AllocHGlobal() is not malloc(), while UnixMarshal.AllocHeap() is

> 2. To add some level of type compiler-checked type safety, could one not
> even replace instances of IntPtr with a set of structs each containing
> only an IntPtr?  e.g.
>     struct PSdpList{
>       IntPtr ptr;
>     }
> (Must go and read that document!)

That might be possible, I haven't tried it.  I imagine it will work.

What is also possible is to use unsafe pointers:

        struct sdp_list_t {}
        static class NativeMethods {
                internal static unsafe extern sdp_list_t* 
                    sdp_list_append(sdp_list_t* list, IntPtr d);

Alas, this requires compiling with /unsafe, and is not CLS compliant,
but that might not matter either.

> 3. Is the format of System.Guid likely to be the same format as a
> SDP/general Linux expects it?

It's not the same format, but it's the same size -- 16 bytes -- which is
most of what matters.  (The SDP uses "uint128_t", which is a byte[16],
while System.Guid uses an int, two shorts and 8 bytes, but they're both
the same size.)

 - Jon

More information about the Mono-list mailing list