2

While using SlimTune to profile a C# application, I find that when profiling native functions is enabled there are lots of entries for a function called "CoUninitializeE." CoUninitialize seems to be related to COM objects, however I'm not directly using any Com objects, and Google has no information about the version ending with an E.

Does anyone have knowledge of what this function is/how to reduce the amount of time spent on it? (For instance, is it related to memory management, so that reducing memory allocations or deallocations would help?)

Edit

It appears the function's name is actually "CoUninitializeEx" and that SlimTune is just chopping off a letter for some reason. I still would appreciate knowledge of what leads to this function being called.

Corey Staten
  • 545
  • 4
  • 12
  • AFAIK There is no CoUnitializeEx. Can you post a screenshot? CoInitialize/Ex & CoUninitialize exist to register threads with the COM library. I'd assume that the main thread is always registered with the library, even if you don't supply a thread attribute (STAThread/MTAThread) on the main entry point. – Ritch Melton Sep 28 '11 at 21:03
  • CoUninitializeEx also seems to be calling CorLaunchApplication, which calls TranslateSecurityAttribute, which calls GetAddrOfContractShutoffFla..., which calls SetCounterName, which calls WaitForSingleObject, which calls WaitForSingleObjectEx. A lot of these functions seem COM centered, but I'm not (directly) using any COM objects that I know of. The only standard library I'm using is System.Math. – Corey Staten Sep 28 '11 at 21:13

1 Answers1

3

CoInitalizeEx() and CoUninitialize() are pretty core in Windows programming. They respectively initialize and shutdown COM on a thread. The CLR calls these functions automatically before and after a Thread runs. It is pretty hard to avoid using COM in a .NET program, it is the basic extensibility model for native Windows code. Quite invisible, thanks to the many wrapper classes in the .NET framework that hides the plumbing.

The generic diagnostic is that you use a lot of threads. Yes, expensive. The thread pool is a workaround.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thanks Hans; the problem is that I'm not visibly using any threads. The only thing done by the function in question is: arithmetic, looping/comparison, memory allocation (double's via new double[]), and calling Math.Log. Does the call to Math.Log somehow create a new thread? – Corey Staten Sep 29 '11 at 15:06
  • No it doesn't. Not sure what you are looking for, it you enable profiling of native code then it is guaranteed that you'll see this function. Since you cannot actually change any of this code, maybe you are better off just not looking at it? – Hans Passant Sep 29 '11 at 15:12
  • Specifically I'm looking for the types of programming that are related to this; CoUninitializeE is taking up to 40% of my programs time. It shows up in some functions, but not in others, so it's not just a constant overhead on calling functions. Since memory allocation and Math.Log are the only "native" calls I seem to be using, I was wondering if it was related to one of these. I.E., if it's related to Math.Log then I could try and optimize my function to call Math.Log less. – Corey Staten Sep 29 '11 at 15:32
  • You are getting garbage profiler results. Not just the extra E. CoUninitialize is only called at thread exit. Get another one, good ones cost money. – Hans Passant Sep 29 '11 at 15:37