title: How to optimize this toString() member function?
body: <p>I have a <code>Vector2D</code> object that returns a string representation of its current coordinates, which is called <code>Vector2D::toString()</code>. Since <code>Vector2D::toString()</code> is potentially called upon frequently, I'm wondering if there's a faster way to return a string of the coordinates. </p>
  
  <pre><code>string Vector2D::toString()
  {
      char buffer[64];
      int length;
  
      sprintf_s(buffer, 64, "(%.2f, %.2f)", m_x, m_y);
  
      return string(buffer, strlen(buffer));
  }
  </code></pre>
  
  <p>I feel it's doing too much work, but I could be wrong. How can this be optimized?</p>
  
  <p>Updated:</p>
  
  <pre><code>string Vector2D::toString()
  {
      static char buffer[64];
      static int length;
  
      length = sprintf_s(buffer, 64, "(%.2f, %.2f)", m_x, m_y);
  
      return string(buffer, length);
  }
  </code></pre>