为什么新/ malloc的失败在Win 64,虽然有足够的可用内存? [英] Why does new / malloc fail on Win x64 although there is plenty of free RAM?

查看:353
本文介绍了为什么新/ malloc的失败在Win 64,虽然有足够的可用内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个强烈的递归函数,创建一个(很小)的std :: multimap中本地使用各种功能的实例(其中递归到的malloc /释放calloc 在标准库)。经过几百递归新的失败,虽然我使用的Windows XP x64的原生64位应用程序。该机具有10 GB内存,应用程序只使用大约1GB。没有其他大的应用程序正在运行。

I have a strongly recursive function, that creates a (very small) std::multimap locally for each function instance using new (which recurses to malloc/calloc in the std lib). After some hundred recursions new fails although i am using a native 64Bit application on Windows XP x64. The machine has 10 GB RAM, The application only uses about 1GB. No other big apps are running.

这发生在几分钟启动程序并启动递归函数后。递归函数被调用约150.000倍在这一点上有可能最大。递归几百的。出现的问题是不是一个堆栈溢出。

This happens a few minutes after starting the program and starting the recursive function. The recursive function has been called about 150.000 times at this point with a probably max. recursion of some hundreds. The problem occurring is not a stack overflow.

我使用Visual Studio 2005和是dinkumware STL。故障发生在一个发布版本。

I am using Visual Studio 2005 and the dinkumware STL. The fault occurs in a release build.

编辑: 好吧,这里是一些code。 我重新安排了code现在,把图栈上,但它使用新的初始化 - 那里它失败。我也试着用一个std :: multimap中,而不是hash_multimap。所有这些模具没有改变的行为。

Ok, here is some code. I rearranged the code now and put the map on the stack, but it uses new to initialize - there it fails. I also tried with a std::multimap instead of hash_multimap. All of this die not change the behavior.

    int TraceBackSource(CalcParams *CalcData, CKnoObj *theKno, int qualNo, 
                            double maschFak, double partAmount, int MaschLevel, char *MaschID, 
                            double *totalStrFlow, int passNo, 
                            CTraceBackData *ResultData)

{   typedef std::hash_multimap<double, CStrObj *>StrFMap;
    StrFMap thePipes;

        for(...)
        {  
            ...
            thePipes.insert(std::make_pair(thisFlow, theStr));
        }

        // max. 5 elements in "thePipes"
        for(StrFMap::iterator it = thePipes.begin(); it != thePipes.end(); it++)
        {
            ...
            try
            {
                TraceBackSource(CalcData, otherKno, qualNo, maschFak * nodeFak, nodeAmount, SubMaschlevel, newMaschID, totalStrFlow, passNo, ResultData);
            }
            catch(std::exception &it)
            {   
                    Trace(0, "*** Exception, %s", it.what()); 
                    return 0;
            }

            return 0;
        }
}

有趣的是,第一个故障运行到catch处理,颇有几分后来我结束了访问冲突和一个损坏的堆栈。

Interestingly, the first failure runs into the catch handler, quite a bit later on i end with a ACCESS VIOLATION and a corrupted stack.

推荐答案

您一些建议一个容易拖欠1MB堆栈大小(c150K×8)。因此,从快看看你的code(以及地图::插入特别是不提供的'...'code)如果您正在运行到一个互动stackoverflow.com:)

Your number suggests an easily defaulted 1MB stacks size (c150K x 8 ). So from a quick look at your code (and that map::insert especially and not providing the for'...' code ) you are running into an interaction with stackoverflow.com :)

您可能正在打它为你运行它的操作系统。在Windows上使用VS连接器setttings或使用editbin.exe或一些异国情调的不可移植的API,三倍的堆栈大小,看它是否显著的异常变化时所观察到的递归计数。

You are probably hitting it for the OS you're running it on. On Windows use the VS linker setttings or use editbin.exe or some exotic unportable api, triple your stack size and see whether it significantly changes the observed recursive count at time of exception.

这篇关于为什么新/ malloc的失败在Win 64,虽然有足够的可用内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆