title: error with using memcpy
body: <p>I try to connect c++ to matlab  for figure function. for the example </p>
  
  <pre><code>Engine *m_pEngine;
  m_pEngine = engOpen("null"); //open matlab engine
  
  const int arraysize = 1000;
  const double degTorad = .0174;
  
  double SinArray[arraysize];
  double CosArray[arraysize];
  double Degrees[arraysize];
  for (int iii = 0; iii &lt; arraysize; iii++)
  {
  Degrees[iii] = iii;//gets the degree
  SinArray[iii] = sin(iii*degTorad);
  CosArray[iii] = cos(iii*degTorad);
  
  }
  cout &lt;&lt; "Example 1 or 2?"&lt;&lt;"\n";
  char Sim = '1';
  cin &gt;&gt; Sim;
  
  // example 1 below
  // we will pass an entire array to be plotted
  
  if (Sim == '1')
  {
  mxArray* SIN = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
  memcpy((void *)mxGetPr(SIN), (void *)SinArray, sizeof(double)*arraysize);
  engPutVariable(m_pEngine, "SinGraph", SIN);
  
  mxArray* COS = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
  memcpy((void *)mxGetPr(COS), (void *)CosArray, sizeof(double)*arraysize);
  engPutVariable(m_pEngine, "CosGraph", COS);
  
  mxArray* DEG = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
  memcpy((void *)mxGetPr(DEG), (void *)Degrees, sizeof(double)*arraysize);
  engPutVariable(m_pEngine, "Degrees", DEG);
  
  engEvalString(m_pEngine, "figure('units','normalized','outerposition',(0 0 1 1))"); //opens up matlab figure window
  engEvalString(m_pEngine, "plot(Degrees,SinGraph,'r',Degrees,CosGraph,'b'),grid minor,title('our Matlab Plot')");
  
  system("pause");
  }
  </code></pre>
  
  <p>it runs well and I can get the correct results. that means the environment setting in my computer is correct. but when run the code below:</p>
  
  <pre><code>for (int i = 0; i &lt; 141; i++)    
      {
          x.push_back(((-141 / 2 + 1 - 1+i)*0.0003));
          y.push_back(((-141 / 2 + 1 - 1+i)*0.0003));
      }
  
  engine *m_pEngine;
  m_pEngine = engOpen("null"); //open matlab engine
  
  mxArray *xxx = mxCreateDoubleMatrix(1, 141, mxREAL);
  memcpy((void*)mxGetM(xxx), &amp;x, sizeof(double)*x.size());
  engPutVariable(m_pEngine, "x", xxx);
  
  
  mxArray *yyy = mxCreateDoubleMatrix(1, 141, mxREAL);
  memcpy((void*)mxGetM(yyy), &amp;y, sizeof(double)*y.size());
  engPutVariable(m_pEngine, "y", yyy);
  </code></pre>
  
  <p>it breaks for: Unhandled exception at 0x00007FFFB193AA69 (msvcr120d.dll) in PlanarforwardC.exe: 0xC0000005: Access violation writing location 0x0000000000000001.
  and it also says that:
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwcholmod.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\graphics_util.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwplatform_res.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Windows\System32\msimg32.dll'. Symbols loaded.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwamd.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwcolamd.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwblas.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwlapack.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. Symbols loaded.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwbinder.dll'. Cannot find or open the PDB file.
  'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwompwrapper.dll'. Cannot find or open the PDB file.
  DBGHELP: Symbol Search Path: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug
  DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\m_interpreter.pdb - file not found
  DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\dll\m_interpreter.pdb - file not found
  DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\symbols\dll\m_interpreter.pdb - file not found
  DBGHELP: y:\R2012bd\build\matlab\bin\win64\m_interpreter.pdb - file not found
  DBGHELP: m_interpreter - export symbols
  DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\msvcr90.amd64.pdb - file not found
  DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\dll\msvcr90.amd64.pdb - file not found
  DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\symbols\dll\msvcr90.amd64.pdb - file not found
  DBGHELP: msvcr90.amd64.pdb - file not found</p>
  
  <pre><code>memcpy((void*)mxGetM(xxx), &amp;x, sizeof(xx));
  </code></pre>
  
  <p>I also tried to find the solution and use double xx[141]and double yy[141]replace vector x and vector y.</p>
  
  <pre><code>mxArray *xxx = mxCreateDoubleMatrix(1, num_x, mxREAL);
  memcpy((void*)mxGetM(xxx), (void*)xx, sizeof(xx));
  engPutVariable(m_pEngine, "x", xxx);
  
  
  mxArray *yyy = mxCreateDoubleMatrix(1, num_x, mxREAL);
  memcpy((void*)mxGetM(yyy), (void*)yy, sizeof(double)*y.size());
  engPutVariable(m_pEngine, "y", yyy);
  </code></pre>
  
  <p>it still didn't work.
  can anyone give me some suggestions about this? I tested line by line and the problem is in :</p>
  
  <p>many thanks</p>