I suggest you ...

extend C# to close gaps for high performance native interop

There are several annoying holes in C# interop handling of native types and parametrics.

1) "ref" struct extension methods. Oddly, this is possible in VB.NET:

' It is possible to change the struct fields, because we have a ref
<Extension()> _
Public Sub SetA(ByRef [me] As FooStruct, newval As Integer)
[me].a = newval
End Sub

We would like to do the same thing in C#. It would be fine if ref extension methods were limited to struct/value types.

2) Take the address of a parametric value type or value-type-array for use in high performance interop:

public unsafe void Foo<T>(T[] data) where T : struct {
fixed (void *rawdata = &data) {
.. do something to hand the raw pointer to a native call
}
}

3) Efficient access to IL cpyblk instruction, though some kind of "raw" data-copy intrinsic. This would allow copying between two unmanaged pointers in a portable way without resorting to DllImport of memcpy. Something like Runtime.InteropServices.Memory.Copy() or Marshal.Copy(IntPtr dest,IntPtr src,int length)

4) Provide parametric Marshal.Copy<T>(T data,...) and Marshal.Copy<T>(T[] data_Arr,...)... This can be built using the above mechanisms, though it would be nice if it were provided in the Marshal namespace.

-----

SharpDX is a high performance DirectX wrapper which is works around some of these problems with IL injection. It would be nice to see C# improved to handle these things more natively, or alternatively, to receive support for inline-IL so these oversights can be solved more naturally.

http://www.sharpdx.org/forum/8-internals/1846-awesome-library-question-about-interop

https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX/Interop.cs

https://github.com/sharpdx/SharpDX/blob/master/Source/Tools/SharpCli/InteropApp.cs

13 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    AnonymousAnonymous shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    Thank you for your suggestion! While we aim to respond to every suggestion, we are closing older ones that don’t have enough votes so newer ones from you can move to the top. If this suggestion is still important to you, feel free to open it again.

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base