Search code examples
ccudaiteratorthrust

If a Thrust device_vector's .begin() iterator is stored, does it still point to the correct position after a resize()?


For instance:

thrust::device_vector<float> vec(...);
thrust::device_vector<float>::iterator i = vec.begin();
vec.resize(...);    // vec may get reallocated and moved in memory here

Now, has vec.begin() also updated and still point validly to the start of vec?


Solution

  • Upon resizing, if the vector originally did not have enough space, your iterator will be invalidated, so you'd have to recall vec.begin() to get a new, valid iterator.