Interop (.NET 1.1) Performance Guidelines
From Guidance Share
- J.D. Meier, Srinath Vasireddy, Ashish Babbar, and Alex Mackman
Contents |
[edit]
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.
[edit]
Code Access Security (CAS)
- Consider using SuppressUnmanagedCode for performance-critical trusted scenarios.
- Consider using TLBIMP /unsafe for performance-critical trusted scenarios.
[edit]
Marshal.ReleaseComObject
- Consider calling ReleaseComObject in server applications.
- Do not force garbage collections with GC.Collect.
[edit]
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.
[edit]