windows 共同初始化失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2210028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:53:40  来源:igfitidea点击:

CoInitialize Failed

c++windowscom

提问by ipr

We had multi-threaded application. Each thread has to invoke with CoIntialize when it is iniatialized as we use some C++ COM object for our DB operation. The application is working fine for longer time in the production env. But suddently the CoIntialize() API in thread init function failed with below error ThreadInit; HRESULT: 80070008 : Not enough storage is available to process this command. OS : Windows Server 2003 R2 with SP2. I found work a around in stackoverflow to increase heapsize for console application from 512 KB to 1MB in windows registry. I can do that. But I want to know what is the possible reason for this to happen first. The env did not changed recently. There are several other process running in that machine they can invoke Coinitialize without any issue. It failed for only two process. Thanks in advance

我们有多线程应用程序。每个线程在初始化时都必须使用 CoIntialize 调用,因为我们将一些 C++ COM 对象用于我们的数据库操作。该应用程序在生产环境中可以正常工作更长的时间。但是突然之间,线程初始化函数中的 CoIntialize() API 失败了,出现了以下错误 ThreadInit; HRESULT:80070008:没有足够的存储空间来处理此命令。操作系统:带有 SP2 的 Windows Server 2003 R2。我在 stackoverflow 中找到了一个解决方法,将控制台应用程序的堆大小从 512 KB 增加到 Windows 注册表中的 1MB。我可以做到。但我想知道首先发生这种情况的可能原因是什么。环境最近没有改变。那台机器上还有其他几个进程在运行,它们可以毫无问题地调用 Coinitialize。只有两个过程失败。提前致谢

采纳答案by Reed Copsey

CoInitialize"initializes the COM library on the current thread", which does have a memory requirement.

CoInitialize“在当前线程上初始化 COM 库”,这确实有内存要求。

My guess is that your production environment hit a point where the application's heap size was not adequate to initialize COM on the new thread. Perhaps you hit a scenario where you allocated more threads than previously, even if the application wasn't running as long.

我的猜测是您的生产环境达到了应用程序的堆大小不足以在新线程上初始化 COM 的点。也许您遇到了分配比以前更多线程的情况,即使应用程序运行时间不长。

Raising the heap size would fix this, since it would allow those threads to initialize properly.

增加堆大小可以解决这个问题,因为它可以让这些线程正确初始化。

回答by Hans Passant

Something is leaking somewhere. Start by assuming it is your program. You can observe its handle usage with Taskmgr.exe, Processes tab, View + Select columns and tick Handles, GDI objects and USER objects. Observe these numbers while your app is running. If they climb steadily then you're leaking handles in your code. The show is over once a column reaches 10,000.

有什么东西在某处泄漏。首先假设它是您的程序。您可以通过 Taskmgr.exe、进程选项卡、查看 + 选择列并勾选句柄、GDI 对象和 USER 对象来观察其句柄使用情况。在您的应用程序运行时观察这些数字。如果它们稳步攀升,那么您的代码中就会出现句柄泄漏。一旦专栏达到10,000,节目就结束了。

A more obscure explanation is running out of space in the kernel memory pool. Also visible in Taskmgr from the Performance tab.

一个更模糊的解释是内核内存池中的空间不足。也可以从性能选项卡在 Taskmgr 中看到。

回答by mloskot

Is there any chance you call CoInitializefrom DllMain, all the more, on DLL_THREAD_ATTACH? This would most likely cause a deadlock or lead to leaks.

您是否有机会在 DLL_THREAD_ATTACH 上从 DllMain调用CoInitialize?这很可能会导致死锁或导致泄漏。

I suppose a memory leak occurs somewhere around index of Thread Local Storage

我想内存泄漏发生在线程本地存储的索引附近