使用插入迭代器复制算法... [英] Copy algorithm with insert iterators...
问题描述
我养成了经常使用副本和插入
迭代器的习惯。在某些情况下,我会以这种方式处理大量数据。
有人能给我一个普遍的感觉,那就是我有多大的表现能够获得
使用这种技术而不是使用''copy''直接复制到元素到位的
容器中?
谢谢,
d
I have gotten into the habit of often using copy along with an insert
iterator. There are scenarios where I process quite a lot of data this way.
Can someone give me a general feel as to how much of a performance hit I''m
taking using this technique versus using ''copy'' to copy directly into a
container with elements in place?
Thanks,
d
推荐答案
" deancoo" < S2 ******* @ yahoo.ca>在消息中写道
news:k7KWd.11823
"deancoo" <s2*******@yahoo.ca> wrote in message
news:k7KWd.11823
KI2.9259@clgrps12 ...
KI2.9259@clgrps12...
我养成了习惯经常使用副本和插入
迭代器。在某些情况下,我会以这种方式处理大量数据。有人能给我一个普遍的感觉吗?我正在使用这种技术,而不是使用''copy''直接复制到具有元素的
容器中? br />
谢谢,
d
I have gotten into the habit of often using copy along with an insert
iterator. There are scenarios where I process quite a lot of data this
way. Can someone give me a general feel as to how much of a performance hit
I''m taking using this technique versus using ''copy'' to copy directly into a
container with elements in place?
Thanks,
d
一如既往,如果你有严格的性能要求,你应该这样做
时间研究。但是,你要求一般的感觉。一般来说,它不是坏bb b。比如使用std :: vector你可以做
std :: vector< double> v(10000);
std :: copy(ptr,ptr + 10000,& v [0]);
将保存10000次push_back操作,但现在你必须在覆盖它们之前将
初始化10000倍到0.0。你正在使用的
替代品可能是
std :: vector< double> v;
v.reserve(10000); //不要忘了这个
std :: copy(ptr,ptr + 10000,std :: back_inserter(v));
每一步都有一点记账 - 可能会增加一个最后
指针 - 但是使用复制构造函数进行初始化。如果你没有在std :: copy之前保留足够的内存,那么对象将不得不多次重新分配
内存。
-
Cy
http ://home.rochester.rr.com/cyhome/
" Cy Edmunds" < CE ****** @ spamless.rochester.rr.com>在消息中写道
news:wn ******************* @ twister.nyroc.rr.com ...
"Cy Edmunds" <ce******@spamless.rochester.rr.com> wrote in message
news:wn*******************@twister.nyroc.rr.com...
deancoo < S2 ******* @ yahoo.ca>在消息中写道
新闻:k7KWd.11823
"deancoo" <s2*******@yahoo.ca> wrote in message
news:k7KWd.11823
这篇关于使用插入迭代器复制算法...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!