title: C++: Will structure be copied properly?
body: <p>I have a pointer to a structure and I need to implement a method that will copy all of the memory contents of a structure. Generally speaking I need to perform a deep copy of a structure.</p>
  
  <p>Here's the structure:</p>
  
  <pre><code>typedef struct { 
      Size2f spriteSize;
  
      Vertex2f *vertices;
  
      GLubyte *vertex_indices;
  } tSprite;
  </code></pre>
  
  <p>And here's the method I've implemented that should copy the structure:</p>
  
  <pre><code>tSprite* copySprite(const tSprite *copyFromMe)
  {
  
      tSprite *pSpriteToReturn = (tSprite*)malloc( sizeof(*copyFromMe) );
  
      memcpy(pSpriteToReturn, copyFromMe, sizeof(*copyFromMe) );
  
      return pSpriteToReturn;
  }
  </code></pre>
  
  <p>The problem is that I'm not sure that arrays "vertices" and "vertex_indices" are going to be copied properly. What is going to be copied in this way? Address of the array or the array itself?</p>
  
  <p>Should I copy the arrays after copying the structure? Or is it enough just to copy the structure?</p>
  
  <p>Something like this:</p>
  
  <pre><code>...
  pSpriteToReturn-&gt;vertices = (Vector2f*)malloc( sizeof(arraysize) );
  memcpy(pSpriteToReturn-&gt;vertices, copyFromMe-&gt;vertices, sizeof(arraysize) );
  ...
  </code></pre>
  
  <p>Thank you in advance.</p>