小编use*_*822的帖子

计算效率高的C++ - 一般阅读

我的工作主要是高性能的"科学"计算.我已经做了大约15年了,但直到最近才意识到我的软件浪费了计算时间.简而言之:我编写高效C++代码的方式不再适用.

我不时会看到一段由一些孩子编写的代码,它与我的计算基本相同(相同的算法,类似的方法),但是 - 神奇地! - 表现得更快.在大多数情况下,我甚至无法追踪差异的起源!

我的问题是:我如何学习现代C++代码优化的艺术?也许在SSE,缓存/内存对齐问题上有什么问题?欢迎任何书籍,PDF,文章,练习或网站的建议!

PS.我很清楚这些技巧:

  • 太一般(例如'使用分析器','使用好的算法','去多线程')
  • 琐碎(例如'避免虚函数','Do ++ i代替i ++','启用-O3')
  • 有问题的(例如'使用reinterpret_cast重复使用内存<>','Tabularize正弦和余弦','写入内联汇编')
  • 荒谬(例如'做模板元编程')

这些不是我要问的.

c++ optimization performance

10
推荐指数
2
解决办法
703
查看次数

调用基类'构造函数时隐式'this'

我希望以下片段解释一切:

struct TBase {
  virtual void f() {}
};

struct TDerived : public TBase {
    TDerived() {
      /* These are all fine either under GCC 4.4.3, ICC 12 and Comeau online: */
      f();
      this->f();
      TBase::f();
      this->TBase::f();

      /* This one fails under Comeau: */
      TBase::TBase();

      /* While this one fails in every case: */
      //this->TBase::TBase();

      /* e.g. GCC says:
         test.cpp: In constructor ‘TDerived::TDerived()’:
         test.cpp:17: error: invalid use of ‘struct TBase’  */
    }
    void f() {}
};
Run Code Online (Sandbox Code Playgroud)

问题是:为什么?(即为什么是TBase::TBase()错的,根据Comeau C++?为什么this->TBase::TBase() …

c++ this

1
推荐指数
1
解决办法
129
查看次数

标签 统计

c++ ×2

optimization ×1

performance ×1

this ×1