The most efficient way for fill a vector from an array?
Hi,
I wonder, what is the most efficient STL way to move the values from
an array into a vector of the same kind?
* "move" means, that I dont care about the array afterwards.
* It should be a platform independent way, probably a way how it could
be done
with general C++ features and STL methods if the implementors chose
to implement it.
My general idea would be that there might be something like
(pseudocode):
std::vector<int> vec;
int arr[10] = { 1,2,3, 2,3,4, 3,4,5, 10} ;
std::move( vec.begin(), vec.end(), arr, arr+10); // vec := arr
I am trying to find the best line[s] for my invended "std::move()". I
imagined, there might be something in the STL that would have allowed
by design their implementors to do some very careful pointer-magic, if
they choose to, like that pseudocode specialization here:
template<>
move<T>(vector<T>::interator dst_start, vector<T>::iterator
dst_stop, T* src_start, T* src_stop)
{
if(//dst_start and dst_stop cover the whole of the dst//) {
//set the internal data-pointer of trg to src_start//
} else {
std::swap_ranges(...);
}
}
Maybe there is a general performance-cheap solution I can not see -- a
way the designers of the STL or C++ thought, they leave the library or
language implementors the "door" open for good performance tweaking,
if they set their mind to it.
The hard fact reason for my question is, that I want to read a file
that I could do with a single read()-call into an array[], but I want
it to go into a vector<>, instead. And because it's huge, I want to do
it without twice the memory and without an unneccessary copy.
Maybe what I am asking is related to how to make vector ROMable?
Thanks in advance,
tschau, towi.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]