- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在阅读来自 wikipedia' article-Template metaprogramming 的[编译时代码优化] 时| :
template <int length>
Vector<length>& Vector<length>::operator+=(const Vector<length>& rhs)
{
for (int i = 0; i < length; ++i)
value[i] += rhs.value[i];
return *this;
}
When the compiler instantiates the function template defined above, the following code may be produced:[citation needed]
template <>
Vector<2>& Vector<2>::operator+=(const Vector<2>& rhs)
{
value[0] += rhs.value[0];
value[1] += rhs.value[1];
return *this;
}
The compiler's optimizer should be able to unroll the for loop because the template parameter length is a constant at compile time.
However, take caution as this may cause code bloat as separate unrolled code will be generated for each 'N'(vector size) you instantiate with.
但是,我在编写 TMP 代码时了解到,应该避免循环,因为它是运行时的,模板递归是一种替换。
我在谷歌上搜索编辑并找到 this question手动展开。答案还鼓励使用递归。
那么,我应该依靠编译时代码优化,它能够在编译时使用编译时确定长度(循环结束)展开 for 循环,还是始终使用递归?
我认为来自维基百科的文章鼓励我们依赖 un-roll。可能是我理解错了?
最佳答案
循环展开与模板无关(至少一般而言)。当大小已知时,编译器可以展开循环(它们也可以展开非静态有界循环,但这要困难得多)。
如果您使用模板递归,那仅意味着您可以控制循环展开的方式。
无论如何,不要尝试进行过早的优化...滚动循环不太可能是您的运行时成本问题。让编译器展开至少是免费的,而自己做有点痛苦且容易出错,而且不确定结果是否值得付出努力。
关于c++ - 循环展开和元编程(TMP)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47451841/
我正在使用 springboot 2.1.4 和 EmbeddedTomcat。当我运行服务器时,会创建/tmp/jar_cache###.tmp 。我该如何处理 jar_cache###.tmp?
我有一个简单的上传表单,这里是开始和结束标签: 我在提交时收到 500 内部服务器错误。并且 apache 日志显示以下条目(主机名和 ip 已编辑): [Tue Feb 14 00:08:32
尽管用户是 sudo 用户,但远程主机在运行 Ansible playbook 时仍会引发错误。 "/usr/bin/python: can't open file '/home/ludd/.ansi
在运行 sqoop 命令时,它会运行 java 代码并将它们存储到 /tmp 中。目录所以,它给了我以下错误: (Could not create temporary directory: /tmp/
当我尝试将本地存储库推送到服务器时,我的 Ubuntu 服务器突然出现此错误。谁能帮我解决这个问题。 最佳答案 那是服务器端的 python 说“嘿!这 4 个目录都不是我可以写临时文件的地方!”。检
SQL 2005 中两种类型的临时表@tmp 与#tmp 之间有什么区别? 他们的其他类型是我不知道的吗? 谢谢 最佳答案 #tmp是一个临时表,主要表现得像一个真正的表。它可以有索引,可以有统计数据
我在 Hadoop 文档中看到 1 hadoop.tmp.dir 的默认值是 /tmp/hadoop-${user.name} 但如果我这样设置,当机器重新启动时,我是否丢失数据? 我的意思是,也许我
我发现有关 php 和 /tmp 文件夹的奇怪行为。 Php 在使用 /tmp 时使用另一个文件夹。 PHP 5.6.7,nginx,php-fpm。 我以两种方式执行相同的脚本:通过浏览器和通过 s
当我在hadoop集群上运行java map reduce代码时,出现以下错误消息: -sh-3.2$ hadoop jar PearsonSim1.jar PearsonSim.PearsonDri
我正在尝试编译 Tizen 源代码。编译工具使用rpm构建环境。在编译特定包时,我遇到 rpm 构建问题“Bad exit status from/var/tmp/rpm-tmp.b1DgAt (%b
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我和我的一位同事就此进行了讨论。并且想知道更多人对哪个“可以”更优的看法?PS:如果代码只是一个 hello world 程序,-O3 会产生相同的代码,但我们讨论的是此代码段位于大型项目中间的场景。
我在提交时遇到以下错误, 无法打开 .svn\tmp\tempfile.tmp:访问被拒绝。 当我开始在谷歌搜索这个错误时,我开始知道可能是因为 McAfee 杀毒软件,这个错误可能会出现。如果 Mc
我正在开发一个网站,该网站要求我创建上传 .csv 文件的函数。上传文件时,提示格式错误,并显示以下消息: C:\xampp\tmp\php9F4F.tmp 我应该如何解决该错误,然后将 csv 文件
我正在尝试构建一个 rpm 文件来安装 ATM 驱动程序。构建 rpm 文件的最后一步是使用此 rpmbuild 命令 [anjanu@matrix rpmbuild]$ rpmbuild -bb S
我有一个java spring boot应用程序,它实现了多线程,其中一个线程订阅ZMQ,四个并行线程根据一些预定的时间间隔对接收到的数据执行一些处理。当 jar 在 Linux VM 上运行并使用命
我有一个奇怪的 RPM 问题,我是新手所以请多多包涵...我创建了规范文件,当我运行构建时出现错误: /var/tmp/rpm-tmp.ajKra4: 第 36 行:cd: hero-01: 没有那个
在过去的几年里,我一直在使用 Cruise Control .NET 持续集成服务器,它运行良好。最近,我在启动 WebDashboard 后开始收到此错误。有人对如何解决此错误有任何建议吗?我是不是
情况是此应用程序在/tmp 中需要更多空间。目前我的 tmp 文件夹在 root 的分区中。临时创建指向不同分区的 tmp 符号链接(symbolic link)以利用更大的空间是否安全? 最佳答案
ls -1/tmp/dir/返回: file1.txt file2.txt ls -1/tmp/dir/* 返回: /tmp/dir/file1.txt /tmp/dir/file2.txt 为什么会
我是一名优秀的程序员,十分优秀!