title: Is it possible to deallocate memory for the N last elements of a thrust::device_vector without using resize?
body: <p>I'm using a <code>device_vector</code> in order to store information about an array of user input data. This information is necessary in order to speed things up when I call the second kernel, which runs the main algorithm.</p>
  
  <p>After the end of the first kernel the <code>device_vector</code> will contain only a small amount of important elements. So for example if initially the <code>device_vector</code> has a size of 10000 in the end only 10-20 elements will be describing the user input data.</p>
  
  <p>What I'm doing right now is, I use the function <code>thrust::remove</code> in order to remove the unnecessary values, however if I understand correctly, this function doesn't really remove the unnecessary values, but returns an iterator to the last necessary value.</p>
  
  <p>For example suppose that we have this array:</p>
  
  <pre><code>0 0 0 0 0 5 0 0 8 0 0 0 0 13 0 0
  </code></pre>
  
  <p>if I call <code>remove</code> for value 0, it will do something like this:</p>
  
  <pre><code>5 8 13 0 0 0 0 0 0 0 0 0 0 0 0 0
  </code></pre>
  
  <p>and it will return an <code>end</code> iterator to the last necessary element, which in my case is 13.</p>
  
  <p>However, I would like to use this information for the second kernel, and if I understand correctly, the unnecessary elements will still be allocated, so I would be using memory that I don't need.</p>
  
  <p>My question is, can I, by having the <code>end</code> iterator to the last necessary element, remove the unnecessary elements without using <code>resize</code>?</p>
  
  <p><code>resize</code> isn't very efficient because it removes all the elements, and allocates memory for the necessary elements as well, but the memory is already allocated so I don't see the point of doing this.</p>