Interop (.NET 1.1) Performance Guidelines
From Guidance Share
Jump to navigationJump to search
- J.D. Meier, Srinath Vasireddy, Ashish Babbar, and Alex Mackman
Design Considerations
- Design chunky interfaces to avoid round trips.
- Reduce round trips with a facade.
- Implement IDisposable if you hold unmanaged resources across client calls.
- Reduce or avoid the use of late binding and reflection.
Code Access Security (CAS)
- Consider using SuppressUnmanagedCode for performance-critical trusted scenarios.
- Consider using TLBIMP /unsafe for performance-critical trusted scenarios.
Marshal.ReleaseComObject
- Consider calling ReleaseComObject in server applications.
- Do not force garbage collections with GC.Collect.
Marshaling
- Explicitly name the target method you call.
- Use blittable types where possible.
- Avoid Unicode to ANSI conversions where possible.
- Use IntPtr for manual marshaling.
- Use [in] and [out] to avoid unnecessary marshaling.
- Avoid aggressive pinning of short-lived objects.