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

  • Home
  • SEARCH
  • 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 7997831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:03:43+00:00 2026-06-04T15:03:43+00:00

For the program I’m working on, I frequently need to read input from a

  • 0

For the program I’m working on, I frequently need to read input from a text file which contains hundreds of thousands of integers. For the time being, I’m reading a handful of values and storing them in a vector. Whenever a value I need is not in the vector, I read from the input file again and flush out the old values to make room for the values I’m currently reading in.

I’d like to avoid a situation where I constantly need to read from the input file and I’m wondering how many values I can store in my vector before there will be a problem. max_size() returns 1073741823, so I’m thinking that I can store that many elements but I’m wondering where that memory is being used and if it’s a good idea to have a vector that large.

When you create a vector as so:

int main(){
std::vector<int> vec;
vec.push_back(3);
vec.push_back(4);

return 0;
}

Is that vector now using stack memory? Since your vector contains 2 ints, does that mean that 8 bytes of stack memory is being used?

According to MSDN docs:

For x86 and x64 machines, the default stack size is 1 MB.

That does not seem like a lot of memory. What is an example of a situation where you would want to increase the stack memory? Is there any way in Visual Studio to monitor exactly how much stack and heap memory are currently being used?

Is there anything I can do to prevent constant reading from the input file in a situation like this?

  • 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-06-04T15:03:45+00:00Added an answer on June 4, 2026 at 3:03 pm

    Is that vector now using stack memory?

    The vec object is on the stack, but it internally allocates its memory on the heap as it grows

    EDIT

    Also, instead of reading all the file and storing it in a vector, you could try using a memory mapped file. From what I understand (not having used them myself), you would benefit from page caching and file reading in kernel mode (as the OS will manage the loading of the file on demand).

    Note that this is merely a suggestion on where to pursue your investigation (I think that it might be appropriate, but I am not familiar enough with memory mapped files to tell you more)

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

Sidebar

Related Questions

The program requires an input of an arbitrary large unsigned integer which is expressed
My program is now still running to import data from a log file into
The program that I am working on takes a file and parses it line
program reads the following data from a .txt file: f 3.40 f 4.00 m
A program I am working on right now has to generate a file. Is
The program I'm working on crashes sometimes trying to read data at the address
My program accepts input file names either as command line parameters or in a
My program receives an executable binary file through a TCP socket. I need to
NOTE: program in java, server uses php, and mysql...file is .log or .txt file
My program has 3 text fields, Title, Website, and PictureURL. When I click the

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.