[Mono-dev] RE: Com Interop Patch - mcs

Zoltan Varga vargaz at gmail.com
Wed Jan 11 09:47:54 EST 2006


                                            Hi,

On 1/9/06, Paolo Molaro <lupus at ximian.com> wrote:
>
> > +        public static int AddRef(IntPtr pUnk)
> > +        {
> > +            IntPtr vtable = Marshal.ReadIntPtr(pUnk);
> > +            IntPtr qi = Marshal.ReadIntPtr(vtable);
> > +            // QueryInterface is 2st method
> > +            IntPtr pAddRef = (IntPtr)(qi.ToInt64() + IntPtr.Size);
> > +            AddRefDelegate add_ref = (AddRefDelegate)Marshal.GetDelegateForFunctionPointer(pAddRef, typeof(AddRefDelegate));
> > +            return add_ref(pUnk);
> > +        }
>
> Moving code to the managed side is sometimes the best way to implement
> some things: this method is the proof that sometimes it's an orrible
> idea:-) This stuff shuld be done in the C runtime.
>

   I would argue otherwise. Writing correct runtime code is very hard,
so the less
we write, the less problems we will have later fixing it, adapting it
to a new GC
etc. We have our string copy implementation in managed code, so why not these ?

                               Zoltan



More information about the Mono-devel-list mailing list