title: Is it better to declare a large vector as a member variable or a local variable inside a member function?
body: <p>Let us say we need to process a large vector, which is only locally used inside a member function. Do we have any advantage in declaring it as a member function to save reallocation time? Because everytime a 10000 ints are being created and destroyed? Assume this is running in a mission critical embedded system. And the function is being called repeatedly!</p>
  <pre><code>class Foo {
    Foo() {
    
    }
    size_t update(int val) {
       vector&lt;int&gt; v(10000);
       for (int i = 0; i &lt; 10000; ++i) {
          v[i] = i*i + val;
       }
       return compute(v);
    } 
    
  };
  </code></pre>
  <pre><code>class Foo {
    Foo() {
      v.resize(10000);
    }
    size_t update(int val) {
       for (int i = 0; i &lt; 10000; ++i) {
          v[i] = i*i + val;
       } 
       return compute(v);
    } 
    private:
    vector&lt;int&gt; v; 
    
  };
  </code></pre>