title: std vector performance/alternative
body: <p>I have to process and store data temporarily. Currently I use <code>std::vector::push_back</code> to add data and <code>std::vector::erase</code> to erase elements when max elements is reached. My problem is that I have to process a lot of data and that when the max amount is reached, erasing seems to hit performance. So I decided to add data and erase x elements every y ms, as an optimization. To start, I also reserve a certain amount in the vector. I use a vector because I need the <code>const double *std::vector&lt;T&gt;::data()</code> function to pass the data to somewhere else and I can't have any conversion/copying or anything. It just has to be fast.</p>
  
  <pre><code>std::vector&lt;double&gt; data;
  size_t max; // there are millions of elements, e.g. 2000000
  data.reserve(max);
  
  // happens every x microseconds
  void receive(double val) {
      data.push_back(val);
  }
  
  // timed every x ms
  void update() {
      if (data.size() &gt; max)
          data.erase(data.begin(),data.end()+(data.size()-max));
  }
  </code></pre>
  
  <p>My question is: How can I make this more efficient? By using another container? Is it then still possible to convert the container to a <code>const double *</code>?</p>
  
  <p>I realize just now that I always exceed max with this setup, could that be the reason for the performance drop? Would the following code fix the issue?</p>
  
  <pre><code>if (data.size() &gt; max*0.8)
          data.erase(data.begin(),data.begin()+(data.size()-max*0.8));
  </code></pre>
  
  <p>Thanks in advance!</p>