We know that if we have a vector like
std::vector<int> a_vector;
and this vector has elements, we can have the array of elements from
int *the_array= a_vector.data();
My question is: How can we do the opposite?
int the_array[5]={1,2,3,4,5};
std::vector<int> a_vector;
a_vector.data=the_array; //this does not seem to work
To clarify, I don't wish to copy the values , nor create an array *from * the values but have them in the same memory area.
Also , why am I asking this?
I would like to have this original array, in a managed (unified) area of memory
__device__ __managed__ int the_array[5];
and build the vector to point there.
std::span(c++20) might be a better "container" for this.int *the_array={1,2,3,4,5}is invalid. Second, if you want to control where the data managed by astd::vectorresides, use a custom allocator. If you want to create an array of automatic storage duration, and then have astd::vectormanage that array, my guess is that an allocator for the job will be a hairy job (lots of possibilities of introducing undefined behaviour in response to innocent operations by other code on the vector).