title: vector<PBYTE> getting corrupted c++
body: <p>I understand <code>PBYTE</code> is <code>unsigned char*</code> from <a href="https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types" rel="nofollow noreferrer">Windows Data Types</a>.</p>
  <p>I am calling a function which updates <code>data</code> and <code>dataSize</code>.</p>
  <p>I print the data after I call the function, but once I print the vector that stores all the data, I am not getting the same value.</p>
  <p>Is it possible that the data is getting corrupted?</p>
  <p>This is a function written internally, not open-source.</p>
  <pre class="lang-cpp prettyprint-override"><code>SerializeEvent(__in_z PCWSTR EventName,
       __out_bcount(DataSize)  PBYTE &amp; Data,
      __out                   ULONG &amp; DataSize){}
  </code></pre>
  <p>This function takes in a field and serializes it and <code>data</code> is basically the buffer where the serialize event name is stored, and <code>dataSize</code> is the size for the same.</p>
  <pre><code>PBYTE data=NULL;
  ULONG dataSize=0;
  
  int main(){
      vector&lt;PBYTE&gt; dataVector;
      vector&lt;ULONG&gt; dataSizeVector;
      
      for(int i=0;i&lt;10;i++){
      
          serializeData(event,data,dataSize);
          printf(&quot;%02x &quot;,data); ///-----&gt;a
          dataVector.push_back(data);
          dataSizeVector.push_back(dataSize);
  
      }
      //just want to print the contents of this vector to verify
      for(int i=0;i&lt;dataVector.size();i++){
          printf(&quot;%02x &quot;,dataVector.at(i)); ----&gt; b
      }
      
  }
  </code></pre>
  <p>The print from the first <code>for</code> loop is not matching the print from the second <code>for</code> loop. Am I missing something?</p>
  <p>But doing the same for dataSizeVector is printing similar values...</p>