Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6189829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:28:54+00:00 2026-05-24T02:28:54+00:00

I want to store ~3,000,000 double values at unsigned int indices under VS2010 C++.

  • 0

I want to store ~3,000,000 double values at unsigned int indices under VS2010 C++. I use a std::tr1:unordered_map<unsigned int, double> for this purpose. Unfortunately, when I try to store value number 2^21, an exception is thrown (as if there is only space for 2^21-1 , i.e., some index can only use 20 Bits). I tried to rehash before storing the values, which did not work either.

Finally I ended up with some very basic test program (which showed even a little different behavior, but anyway):

    std::tr1::unordered_map<unsigned int, float> mapOut;
    //mapOut.rehash(SOMESIZE);
    for (unsigned int i=0; i<3000000; i++)
    {
        if (i%1000==0) std::cout << i << std::endl;
        mapOut[i] = 0.0;
    }

Some cases I checked:

1) If I do not rehash at all, the program takes a long break after the output according to i == 32000 (eventually 2^15) and then continues to i == 262000 (2^18). There it holds forever (with 100% CPU load, memory not increasing).

2) If I do a rehash(1000), it comes to i == 65000 (2^16) and holds forever (CPU load 100%, memory not increasing).

3) If I do a rehash(3000000), the loop is successfully finished, but the program never exits – i.e., obviously there is some problem with the destructor.

What is going on there, and even more important: What should I do about it?!

Many thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:28:54+00:00Added an answer on May 24, 2026 at 2:28 am

    The following bug on Connect appears to be related to your problem: Visual C++: std::unordered_map Destructor Performance in Debug Configuration

    The same problem occurs not just in the destructor, but also when the unordered_map is resized. It seems to have something to with invalidating iterators if iterator debugging is enabled.

    They say it has been fixed for VC11. There are also several workarounds listed, but I haven’t tried them.

    A very simple way to solve the performance problem for both debug and release builds is to set _SECURE_SCL=0 and _HAS_ITERATOR_DEBUGGING=0 in the project options under “Configuration Options / C/C++ / Preprocessor / Preprocessor definitions”, which completely disables all iterator debugging. This does also disable some security checks, however, so you need to be more careful in your own code. I believe both of these are the default under release builds already, so you shouldn’t need to change anything there.

    This appears to be related to the problem of your sample code. I’m not sure about the original problem since you didn’t say what exception was thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to store a number with the following 0.000 which is the best
I want to store values in a bunch of currencies and I'm not too
I want to store prices like this in the mysql database: 1000 instead of
Currently I am using a Dictionary<int,node> to store around 10,000 nodes. The key is
I have 200,000 XML files I want to parse and store in a database.
I want to store the current URL in a session variable to reference the
I want to store a large number of sound files in a database, but
I want to store the data returned by $_SERVER[REMOTE_ADDR] in PHP into a DB
I want to store a a c# DateTimeOffset value in a SQL Server 2005
I want to store a large result set from database in memory. Every record

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.