我正在尝试确定 COM 互操作是否正在成为我软件的瓶颈。MSDN 上的这篇文章有助于http://msdn.microsoft.com/en-us/library/ms998579.aspx#scalenetchapt15_topic11。但是我真的没有关于编组的“正常”或“高”值的参考点,以确定它是否会影响性能。谁能给我这个性能计数器的阈值,就像 MSDN 为文章中的其他性能计数器提供的一样。我知道这是一个特定于硬件和应用程序的问题,但我们将不胜感激。
1 回答
I don't think it is possible to indicate a specific threshold for marshalling. It is application dependent. What you should do is measure how long each call takes on average. Write a test application that simply makes a bunch of calls to unmanaged code and time it. Then using the "Chattiness" counter on your application, you should be able to estimate the total cost of the switches between managed and unmanaged code.
I had to do this exact thing a couple of years ago. I was using an unmanaged DLL to read values from a chunk of data. I measured the calls and found it to be relatively expensive due to the high number of calls, so I made a single call to retrieve the chunk of data and then extracted the values from that data in managed code. It was more work to code but provided a fairly significant speed increase.