title: C++: is it safe to work with std::vectors as if they were arrays?
body: <p>I need to have a fixed-size array of elements and to call on them functions that require to know about how they're placed in memory, in particular:</p>
  
  <ul>
  <li><p>functions like <code>glVertexPointer</code>, that needs to know where the vertices are, how distant they are one from the other and so on. In my case vertices would be members of the elements to store.</p></li>
  <li><p>to get the index of an element within this array, I'd prefer to avoid having an <code>index</code> field within my elements, but would rather play with pointers arithmetic (ie: index of <code>Element *x</code> will be <code>x - &amp; array[0]</code>) -- btw, this sounds dirty to me: is it good practice or should I do something else?</p></li>
  </ul>
  
  <hr>
  
  <p>Is it safe to use <code>std::vector</code> for this?</p>
  
  <p>Something makes me think that an <code>std::array</code> would be more appropriate but:</p>
  
  <ul>
  <li><p>Constructor and destructor for my structure will be rarely called: I don't mind about such overhead.</p></li>
  <li><p>I'm going to set the <code>std::vector</code> capacity to size I need (the size that would use for an <code>std::array</code>, thus won't take any overhead due to sporadic reallocation.</p></li>
  <li><p>I don't mind a little space overhead for <code>std::vector</code>'s internal structure.</p></li>
  <li><p>I could use the ability to resize the vector (or better: to have a size chosen during setup), and I think there's no way to do this with std::array, since its size is a template parameter (that's too bad: I could do that even with an old C-like array, just dynamically allocating it on the heap).</p></li>
  </ul>
  
  <hr>
  
  <p>If <code>std::vector</code> is fine for my purpose I'd like to know into details if it will have some runtime overhead with respect to <code>std::array</code> (or to a plain C array):</p>
  
  <p>I know that it'll call the default constructor for any element once I increase its size (but I guess this won't cost anything if my data has got an empty default constructor?), same for destructor. Anything else?</p>