I have a device\_vector H. I want to create a shallow copy of H using selected indices. I call it J. I want to modify elements of J thereby modifying corresponding elements of H.

My attempt below fails to modify the elements of H when I change elements of J. It appears that thrust allocates new memory to J, instead of using the memory allocated to H.

```
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sequence.h>
#include <thrust/execution_policy.h>

#include <iostream>

int main(void)
{
  // H has storage for 4 integers
  thrust::device_vector<int> H(10);
  thrust::sequence(thrust::device, H.begin(), H.end(),1);

  std::cout << "H="<< std::endl;
  thrust::copy(H.begin(), H.end(), std::ostream_iterator<int>(std::cout, ","));
  std::cout<< std::endl;

  thrust::device_vector<int> J(H.begin()+3,H.begin()+9);

  std::cout << "Before modifying J="<< std::endl;
  thrust::copy(J.begin(), J.end(), std::ostream_iterator<int>(std::cout, ","));
  std::cout<< std::endl;

  thrust::sequence(thrust::device, J.begin(), J.end(),10);

  std::cout << "after modifying J="<< std::endl;
  thrust::copy(J.begin(), J.end(), std::ostream_iterator<int>(std::cout, ","));
  std::cout<< std::endl;

  std::cout << "After modifying H="<< std::endl;
  thrust::copy(H.begin(), H.end(), std::ostream_iterator<int>(std::cout, ","));
  std::cout<< std::endl;

  return 0;
}

```