title: Stack Memory /STACK
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>When you create a vector as so:</p>
  
  <pre><code>int main(){
  std::vector&lt;int&gt; vec;
  vec.push_back(3);
  vec.push_back(4);
  
  return 0;
  }
  </code></pre>
  
  <p>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?</p>
  
  <p>According to MSDN docs:</p>
  
  <blockquote>
    <p>For x86 and x64 machines, the default stack size is 1 MB.</p>
  </blockquote>
  
  <p>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?</p>
  
  <p>Is there anything I can do to prevent constant reading from the input file in a situation like this?</p>