English 中文(简体)
无顺序——地图在VS10而不是VS9投掷坏_吗?
原标题:unordered_map throws bad_alloc in VS10 but not in VS9, is this a bug?

我的行为在VC9和VC10之间有所区别。

The following code runs OK in VC9 but in VC10 std::unordered_map throws a bad_alloc exception. The strange thing is that if I recover from the exception future allocations will succeed (the size of the container continues to grow). Also if I use boost::unordered_map it works fine in both compilers.

在实际记忆使用方面,Im在4GB RAM(1.7在使用中)的机器上运行,VC9版本在完成任务之前可达到810德国马克,VC10在~658MB坠毁。

这在VC10中是否是一种ug? 我坐在同一机器上,如果做的工作数量相同,那么怎么能以一个版本而不是另一个版本来持续记忆?

<edit>
Some more information: The first time the exception takes place is when calculating 7,718,688 with a stack depth of 1 (no recursion just main->length). After that it seems to happen for each number that is added to the cache. The cache had 16,777,217 elements in it before the exception happened (according to cache.size()). The interesting thing is that even when insert fails the cache size grows by one so it appears that it doesn t supply the strong exception guarantee (in violation of §23.2.1.11).
</edit>

法典如下:

#include <iostream>
#include <unordered_map>

typedef std::unordered_map<_int64, int> cache_type;

_int64 collatz(_int64 i)
{
    return (i&1)? i*3+1 : i/2;
}

int length(_int64 n, cache_type& cache)
{
    if (n == 1)
        return 1;

    cache_type::iterator found = cache.find(n);
    if (found != cache.end())
        return found->second;
    int len = length(collatz(n), cache) + 1; 
    cache.insert(std::make_pair(n, len)); // this sometimes throws
    return len;
}

int main(int argc, char** argv)
{
    const int limit = 10000000;
    cache_type cache;
    std::pair<int, int> max = std::make_pair(0, 0);
    for (int i = 2; i <= limit; ++i) {
        int len = length(i, cache);
        if (len > max.second)
            max = std::make_pair(i, len);
    }

    std::cout<< "Number with longest orbit is " << max.first 
        << " with a lenght of " << max.second 
        << " cache size is " << cache.size() << std::endl;
}

<edit>
Also can anyone reproduce this behaviour, at one time it disappeared (and re-appeared) so there may be something special about my configuration.
</edit>

最佳回答
问题回答

如果需要重新编制地图薄片表,列入单一元素可导致大量记忆分配。 该图似乎在末端约为0.5GB。 (见上文评论)

也许有些犹豫不决,决定需要多少时间来扩大海面表,这或许可以设想每次翻一番。 因此,这将使用~1.5GB作为旧的+新数据,而散列表正在复制中。

因此,你的方案有可能打上程序记忆的极限。 (见评论)。 如果是的话,可能比VC9的记忆多一点,而且方案的不同运行或建筑分配的记忆会略有不同,因此,VC10有时会打上极限,而VC9则没有打过。

否 第64条有统一要求,即地图在分配中可能无法兑现?

采用长途.,看行为是否改变。

1 - 检查结果记录仪,看看是否有任何事件涉及超出允许配额的程序。

2 - 如果在32个轨道上任,则从3个通用公平市开始使用。

3 - 看看是否有不同的分配机构

4 - 零和10.0的配制版面图,在外表上加有人工尺寸限制器(“安全特征”:-)。 它很可能是具有不同数值的大型企业,其数值为x86和x64。

5 - 围绕分配器和每个分配的印刷规模进行细微总结。 这也将告诉你,如果它真的投下了扔 throw物或摆在它面前的东西。

6 - 如果分配者对从它收到的实际WinNT 标语(并再用9.0表示)表示意见。

7 - 预先确定大块(分析1 GB)。

您在深入的传呼中重击打length (





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签