本文介绍了将矢量归零的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的。


我有一个向量< bool>固定大小N.让我们把它叫做bob。

我很笨笨,即:

bob = vector< bool> (N,假);


当然,由于所有对象的创建,这很慢。


我可以做的比以下内容:

bob.clear(); bob.resize(N,false);




我不介意更改容器类型或条目类型(例如

bool-> char),所以如果你有任何建议,那就开火了




我正试图得到这个真的很快,所以我会招待任何所谓的极端解决方案。

Joseph

Okay.

I have a vector<bool> of fixed size N. Let''s call it bob.
I''m zero''ing bob quite a bit, i.e.:
bob = vector<bool>(N, false);

Naturally, this is quite slow, because of all the object creation.

Can I do any better than the following:
bob.clear(); bob.resize(N, false);
?

I don''t mind changing the container type or the entry type (e.g.
bool->char), so if you have any suggestions in that vein then fire
away.

I''m trying to get this to be really fast, so I''ll entertain any
so-called "extreme solution".
Joseph

推荐答案





怎么样


memset(& bob [i],0,N * sizeof(bob [i]));


内置类型(或任何POD)?但是你不能用非POD来支付



V



How about

memset(&bob[i], 0, N*sizeof(bob[i]));

for built-in types (or any PODs for that matter)? You can''t do it
with non-PODs, however.

V



这篇关于将矢量归零的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:47
查看更多