3 ms·
c++ part is one liner intrinsic which may be supported directly with new .net and several io methods which would be heavy on pinvoke calls like 5 per method if
by dlahoda 8y ago
c++ part is one liner intrinsic which may be supported directly with new .net and several io methods which would be heavy on pinvoke calls like 5 per method if in c#, but these are very simple. so c++ part could be done in c and easily ported to unix. i guess c# should allow for pinvoke strategy like in lua to replace c++ more.
- int_19h 8y agoWhat kind of different strategies did you have in mind? So far as I know, P/Invoke already tries to be as low overhead as possible - e.g. primitive types and blittable structs are just passed as is, with no conversions. The recently added Span<T> is also special-cased for P/Invoke.
- chrisseaton 8y ago> So far as I know, P/Invoke already tries to be as low overhead as possible As low as possible maybe, but there's lots of limiting factors with P/Invoke, such as: - They are not inlined - Registers need to be saved pessimistically - The state at the point of the call is visible to observers outside of code the compiler controls so options for scheduling are constrained - Objects need to be materialised - All parameter values need to be available even if they aren't actually used - Objects passed have to be pinned or given an indirect handle - The caller has to be in a safepoint so GC can keep running - The compiler has to juggle things into place for the C ABI, where it may normally lay things out differently - etc Going through a P/Invoke call is a whole inconvenient circus compared to an intrinsic.