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 6682475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:42:39+00:00 2026-05-26T04:42:39+00:00

I have a map<vector<double>,double> element in my code named EU . I have noticed

  • 0

I have a map<vector<double>,double> element in my code named EU.

I have noticed that the memory usage by my code tends to accumulate until I have used the entire available memory on my machine (going from ~200 MB to ~ 4GB). commenting out stuff in my code I have come to the conclusion that a line that access an element in this map is the one that, one commented out, prevent the memory usage increase.
I access the value using []operator and I thought that this might be because the double values are not exactly the same as those in the map. I then searched for a case where this might be:

std::map<vector<double>,double>::iterator mit = EU.find(s);     
if (mit == EU.end()){
  for (int i = 0; i < 3; i++){
    O.w(s[i]);
  }
  cin.ignore();
}

Here O.w(s[i]) is a function In I class I have created to display stuff on screen/write to hard disk. In this case it is simply printf("%0.10f\n",s[i]) and I use cin.ignore() just to stop the program so I could check the output.
Which also cause the increase in memory usage.
Why is that so and how can I prevent this?

Thanks.

  • 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-26T04:42:40+00:00Added an answer on May 26, 2026 at 4:42 am

    When you access an element in a std::map, if the index has no associate value then a new element is created. So each time you access the map with a new key a new node is created to hold both the new std::vector< double > key and double value.

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

Sidebar

Related Questions

I have some code that adds to a std::vector and a std::map after creating
I have the following C++ code std::map<std::string, std::vector<std::vector<std::vector<double> > > > details details[string][index][index].push_back(123.5); May
So I have a container(any kind, probably std::map or std::vector) which contains objects of
If I have a std::vector or std::map variable, and I want to see the
I have a class in C++ with the following member: map< someEnum, vector<SomeObject*>* >
I have a map for my game, I have a script that on a
If I have a vector<string*> *vect or a map<pair<string*, int*>, string*> *map , how
I have the following two boost::fusion maps. namespace bf = boost::fusion; typedef bf::map<bf::pair<char,float>,bf::pair<int,double>> FusionMap;
I have a map that relates integers to vectors (of objects). These vectors represent
I have a map of a vector of char 's and a vector of

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.