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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:02:06+00:00 2026-05-23T15:02:06+00:00

I have a simple question. I have a few files, one file is around

  • 0

I have a simple question. I have a few files, one file is around ~20000 lines.
It has 5 fields, have some other adt (vectors and lists), but those do not cause a segfault.
The map itself will store a key value, equivalent to about 1 per line.
When I added a map to my code, I would instantly get a segfault, I copied 5000 of 20000 lines, and receive a segfault, then 1000, and it worked.

In java there is a way to increase the amount of virtually allocated memory, is there a way to do so in c++? I have even deleted elements as they are no longer used, and I can get around 2000 lines, but not more.

Here is gdb:

(gdb) exec-file readin
(gdb) run
Starting program: /x/x/x/readin readin

Program exited normally.

valgrind:

HEAP SUMMARY:
==7948==     in use at exit: 0 bytes in 0 blocks
==7948==   total heap usage: 20,206 allocs, 20,206 frees, 2,661,509 bytes allocated
==7948== 
==7948== All heap blocks were freed -- no leaks are possible

code:

 ....
 Flow flw = endQueue.top();
  stringstream str1;
  stringstream str2;
  if (flw.getSrc() < flw.getDest()){
    str1 << flw.getSrc();
    str2 << flw.getDest();
    flw_src_dest = str1.str() + "-" + str2.str();
  } else {
    str1 << flw.getSrc();
    str2 << flw.getDest();
    flw_src_dest = str2.str() + "-" + str1.str();
  }    
while (int_start > flw.getEnd()){
  if(flw.getFlow() == 1){
    ava_bw[flw_src_dest] += 5.5;
  } else {
    ava_bw[flw_src_dest] += 2.5;
  }
  endQueue.pop();
} 
  • 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-23T15:02:07+00:00Added an answer on May 23, 2026 at 3:02 pm

    Be careful erasing elements from a container while you are iterating over the container.

    for (pos = ava_bw.begin(); pos != ava_bw.end(); ++pos) {
        if (pos->second == INIT){
          ava_bw.erase(pos);
        }
      }
    

    I believe this will have pos pointing to the next value but then ++pos will advance it yet again. If erase(pos) resulted in pos pointing at ava_bw.end(), the ++pos will fail.

    I know if you tried this with a vector, pos will be invalidated.

    Edit

    In the while loop you do

    while (int_start > flw.getEnd()){
       if(flw.getFlow() == 1){
          ava_bw[flw_src_dest] += 5.5;
       } else {
          ava_bw[flw_src_dest] += 2.5;
       }
       endQueue.pop();
    }
    

    You need to do flw = endQueue.top() again.

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

Sidebar

Related Questions

Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I have a simple question related to one-line programming. First an example: function test(a)
I have two .csv files containing correlation matrices exported from R. One file contains
I have a simple question. Is there a way ( using reflections I suppose
I have a simple question and wish to hear others' experiences regarding which is
I have a simple question about Java's XML API and I hope there's a
I have a simple question, but I'm about 80% sure that the answer to
I have a simple question that I am posing mostly for my curiousity. What
i have pretty simple simple question (i hope so). How do i change the
I have a simple question concerning Javascript. I am trying to print in a

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.