title: c++, how to make a copy of the destination of a pointer
body: <p>I have following code:</p>
  
  <pre><code>IMAGE *ptrInImage = ptrProcUnit-&gt;GetMeasureImage(0);
  if (ptrInImage == NULL) {
      return(-2);
  }
  BYTE* rs, *rd, *rs2;
  rs = (BYTE*)ptrInImage + sizeof(IMAGE);
  rs2 = (BYTE*)ptrInImage + sizeof(IMAGE);
  </code></pre>
  
  <p>I would need rs2 to point to a exact copy of the destination of rs. Currently when I write data to the rs2 pointer, it is editing also the image that is behind rs. That is not what I need. I would need that rs2 points to an exact copy of rs, and that I write to that copy instead. But I cannot figure out how to do that. </p>
  
  <p>The attempt that gave best results up to now was this, but it gave other problems like access errors.</p>
  
  <pre><code>IMAGE *ptrInImage = ptrProcUnit-&gt;GetMeasureImage(0);
  if (ptrInImage == NULL) {
      return(-2);
  }
  
  
  IMAGE TmpImage;
  IMAGE *ptrTmpImage = ptrProcUnit-&gt;GetImageData(0);
  memcpy(ptrTmpImage, ptrInImage, sizeof(IMAGE));
  
  BYTE* rs, *rd, *rs2;
  rs = (BYTE*)ptrInImage + sizeof(IMAGE);
  rs2 = (BYTE*)ptrTmpImage + sizeof(IMAGE);
  </code></pre>