Appending a device_vector to another ?

Greetings All,

I am looking for a way two take two device_vector and get a resulting list of the two merged.
Is a third buffer necessary ?

ie:

thrust::device_vector<Block>* oldBlocks;
thrust::device_vector<Block>* appendBlocks;
thrust::device_vector<Block>* newBlocks;

newBlocks->resize( oldBlocks->size() + appendBlocks->size() );
newBlocks->insert( newBlocks->begin(), oldBlocks->begin(), oldBlocks->end() );
newBlocks->insert( newBlocks->begin() + oldBlocks->size(), appendBlocks->begin(), appendBlocks->end() );
delete oldBlocks;
oldBlocks = newBlocks;

Or is there a way to append to the oldBlocks without creating newBlocks ? Follow up question, when I insert, then call delete, is the insert a copy of the data or is it inserted by reference ?

It seems to me that something like this should work:

$ cat t112.cu
#include <thrust/device_vector.h>
#include <thrust/copy.h>
#include <iostream>

int main(){

   int a[] = {1, 2, 3};
   int b[] = {4, 5, 6};
   thrust::device_vector<int> va(a, a+(sizeof(a)/sizeof(a[0])));
   thrust::device_vector<int> vb(b, b+(sizeof(b)/sizeof(b[0])));
   va.insert(va.end(), vb.begin(), vb.end());
   thrust::copy(va.begin(), va.end(), std::ostream_iterator<int>(std::cout, ","));
   std::cout << std::endl;
}
$ nvcc -o t112 t112.cu
$ ./t112
1,2,3,4,5,6,
$

Perhaps I am not grasping your question.

Regarding follow up, I think that question is not unique to thrust. A vector uses an array for underlying storage, so I don’t know what it means for something to be “inserted by reference”. As near as I can tell, such a concept would break array indexing.

internally, it uses third buffer anyway. Vector should use continuous memory and there is no realloc() CUDA equivalent