title: Declaring vector as global variable in C++
body: <p>Is it a good practice to declare a vector as global in C++?</p>
  
  <p>This is what I did.</p>
  
  <pre><code>#include &lt;vector&gt;
  std::vector&lt;int&gt; vec;
  </code></pre>
  
  <p>My program compiles successfully, but I am not sure whether this could lead to a runtime
  error under certain  circumstances. According to my understanding, the memory for a global variable will be allocated at compile time, and the compiler may reserve a limited amount of memory to which this vector can expand. Upon hitting this limit, what is being written can eat into the memory used by another variable.</p>
  
  <p>Please advise.</p>