将矢量归零的最快方法?

编程入门 行业动态 更新时间:2024-10-18 12:22:48
本文介绍了将矢量归零的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好的。 我有一个向量< 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

推荐答案

哦。 我应该指出的另一件事是N非常小: N = 3 (根据命令行的不同,它可能小于3,但不会超过。) Joseph Oh. The other thing I should point out is that N is really small: N=3 (Depending upon the command-line, it may be less than 3, but not greater.) Joseph

Joseph Turian写道: Joseph Turian wrote: 好的。 我有矢量< bool>固定大小N.让我们把它叫做bob。我对于bob很零,即: bob = vector< bool>(N,false); 当然,由于所有对象的创建,这都很慢。 我可以做得比以下更好: bob.clear(); bob.resize(N,false); ? 我不介意更改容器类型或条目类型(例如 bool-> char),所以如果你有这方面的任何建议,那就开火了。 我正在努力让这个很快,所以我会招待任何所以 - 称为极端解决方案。 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".

怎么样 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

为了娱乐任何解决方案,我相信这是最快可能的方式0-init聚合POD: bool bob [123] = {0}; 当然如果你已经分配了阵列,你就不能这样做。 小心, John Dibling In the interest of entertaining any solution, I believe that this the fastest possible way to 0-init an aggregate of PODs: bool bob[123] = {0}; Of course if you already have allocated the array, you can''t do this. Take care, John Dibling

更多推荐

将矢量归零的最快方法?

本文发布于:2023-11-13 02:13:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583131.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矢量   最快   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!