B
buchtak
Hi,
is there a simple way, how to make a shallow copy of a std::vector
without unnecesary memory allocation?
I have a vector myVec and function, which takes as one of the
arguments reference to a std::vector<int>, something like
std::vector<int> myVec;
....
void foo( std::vector<int> &v ) { ... }.
What i need to do is to process (by foo()) only part of the vector
myVec (for example second half, or some interval). The straightforward
solution may be to make a deep copy of the second half of myVec and
then pass it to the function foo(), or to change the header of the
function foo() to take arguments like int first and int size (or
iterators), but that's unhandy for me. Is there a simple way to
initialize a new vector to point to the same memory as myVec, but
setting _Myfirst member to the half of myVec array, which i could then
pass to the foo()? Or is this kind of solution silly and even worse?
Thx for advice.
is there a simple way, how to make a shallow copy of a std::vector
without unnecesary memory allocation?
I have a vector myVec and function, which takes as one of the
arguments reference to a std::vector<int>, something like
std::vector<int> myVec;
....
void foo( std::vector<int> &v ) { ... }.
What i need to do is to process (by foo()) only part of the vector
myVec (for example second half, or some interval). The straightforward
solution may be to make a deep copy of the second half of myVec and
then pass it to the function foo(), or to change the header of the
function foo() to take arguments like int first and int size (or
iterators), but that's unhandy for me. Is there a simple way to
initialize a new vector to point to the same memory as myVec, but
setting _Myfirst member to the half of myVec array, which i could then
pass to the foo()? Or is this kind of solution silly and even worse?
Thx for advice.