title: Most efficient way to implement matrix on large inputs in c++?
body: <p>I am trying to figure out the best way to create a matrix in C++. So far I have two options I have come up with: </p>
  
  <p>1) One vector which stores all the data in one "line," but using modulo and arithmetic, can be accessed like a 2D table. </p>
  
  <p>OR  </p>
  
  <p>2) A vector holding pointers to other vectors, such that the original vector represents set columns and the vectors it points to contain the values going down the rows of each column. </p>
  
  <p>For example, if we have a table like so:</p>
  
  <pre><code>Name  |  Course   |  Grade
  Allen | Chemistry |  76
  Rick  | English   |  84
  Mary  | Physics   |  93
  </code></pre>
  
  <p>My first example would store all the data in one vector like this:</p>
  
  <pre><code>my_vec = {Name, Course, Grade, 
            Allen, Chemistry, 76, 
            Rick, English, 84, 
            Mary, Physics, 93}
  </code></pre>
  
  <p>(assume the heterogeneous nature of the values stored in the same vector is not a problem for now)</p>
  
  <p>My second example would store the data like so:   </p>
  
  <pre><code>vec1 = {Name, Course, Grade}; 
  </code></pre>
  
  <p>Where each spot would contain a pointer to a vector (3 "sub" vectors in this ex.)</p>
  
  <pre><code>Name -&gt; name_vec = {Allen, Rick, Mary}
  Course -&gt; course_vec = {Chemistry, English, Physics}
  Grade -&gt; grade_vec = {76, 84, 93}
  </code></pre>
  
  <p>Some requirements on the matrix:</p>
  
  <ul>
  <li><p>It needs to be growable, which is why I have elected to use vectors in my examples.</p></li>
  <li><p>It needs to be able to handle large amounts of data efficiently</p></li>
  <li><p>It must be able to support row insertion (at the end), row deletion (from the middle), appending one matrix to another (by adding its columns onto the left end of the original matrix, if we visualize it like a table)</p></li>
  </ul>
  
  <p>Does anyone know if one of these options would be significantly more efficient than the other on large inputs? Alternately, does anybody have a better suggestion for implementing this matrix?</p>