title: memset on vector is making its size 0
body: <p>I was trying to clear all data in a vector without changing its size using <code>memset</code>. But after <code>memset</code> operation size of vector becomes 0. Here is the exact code:</p>
  
  <pre><code>std::vector&lt;T&gt; buckets[2];
  MAX_BUCKET_SIZE=16;
  </code></pre>
  
  <p>Constructor:</p>
  
  <pre><code>buckets[0].resize(MAX_BUCKET_SIZE);
  std::cout &lt;&lt; "Actual size0 " &lt;&lt; buckets[0].size() &lt;&lt; std::endl;
  buckets[1].resize(MAX_BUCKET_SIZE);
  std::cout &lt;&lt; "Actual size1 " &lt;&lt; buckets[1].size() &lt;&lt; std::endl;
  </code></pre>
  
  <p>in a function:</p>
  
  <pre><code>std::cout &lt;&lt; "Actual size2 0 " &lt;&lt; buckets[0].size() &lt;&lt; std::endl;
  std::cout &lt;&lt; "Actual size2 1 " &lt;&lt; buckets[1].size() &lt;&lt; std::endl;
  ...
  ...
  while (...){
      delete_data(current_bucket);
  
      std::cout &lt;&lt; "current bucket ** " &lt;&lt; current_bucket &lt;&lt; std::endl;
      std::cout &lt;&lt; "Actual size3 0 " &lt;&lt; buckets[0].size() &lt;&lt; std::endl;
      std::cout &lt;&lt; "Actual size3 1 " &lt;&lt; buckets[1].size() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p><code>delete_data</code> function:</p>
  
  <pre><code>memset(&amp;buckets[bucket_id], 0, sizeof(buckets[bucket_id]));
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Actual size0 16
  Actual size1 16
  Actual size2 0 16
  Actual size2 1 16
  current bucket ** 1
  Actual size3 0 16
  Actual size3 1 0
  current bucket ** 0
  Actual size3 0 0
  Actual size3 1 0
  </code></pre>