This question already has an answer here: What is the difference between g++ and gcc? 10 answers Both are provided by the GCC toolchain, and both are [wrappers around] compiler front-ends, but they are not the same thing: gcc compiles C; g++ compiles C++. The C++ standard library symbols, and various other symbols required by the C++ runtime in order to support your C++ code, are only
这个问题在这里已经有了答案: g ++和gcc有什么区别? 10个答案 两者都由GCC工具链提供,两者都是编译器前端的[wrappers],但它们不是同一件事: gcc编译C; g++编译C ++。 为了支持C ++代码,C ++标准库符号以及C ++运行时所需的各种其他符号仅与后者(默认情况下)链接。 我只是有一个简单的C主程序,并有一个类,VoronoiDiagramGenerator.cpp和VoronoiDiagramGenerator.h是类定义 我想你的意思是一个简单的C ++
I have implemented an algorithm which at some point needs to calculate the sum of the powers of the elements of a vector. The power is a positive double which is constant during the loop. I figured out, that this calculation is currently the bottleneck of my program and wonder if there is a way to speed up the following code snippet: double SumOfPowers(std::vector<double>& aVector,do
我已经实现了一种算法,在某些时候需要计算矢量元素的功率总和。 权力是一个积极的双重,在循环过程中不变。 我想通了,这个计算是目前我的程序的瓶颈,并想知道是否有办法加快下面的代码片段: double SumOfPowers(std::vector<double>& aVector,double exponent) { double help = 0; size_t sizeOfaVector = aVector.size(); for (size_t k = 0; k < sizeOfaVector; k++) { help += st
I have hot spots in my code where I'm doing pow() taking up around 10-20% of my execution time. My input to pow(x,y) is very specific, so I'm wondering if there's a way to roll two pow() approximations (one for each exponent) with higher performance: I have two constant exponents: 2.4 and 1/2.4. When the exponent is 2.4, x will be in the range (0.090473935, 1.0]. When the expo
我在我的代码中有热点,我正在做pow()占用了我执行时间的10-20%。 我对pow(x,y)输入是非常具体的,所以我想知道是否有办法以更高的性能滚动两个pow()近似值(每个指数一个): 我有两个常量指数:2.4和1 / 2.4。 当指数为2.4时,x将在范围内(0.090473935,1.0)。 当指数为1 / 2.4时,x将在范围内(0.0031308,1.0)。 我正在使用SSE / AVX float向量。 如果平台的细节可以被利用,就在! 尽管我对全精度( float
I have looked into several topics to try to get some ideas on how to make a reliable clock with C or C++. However, I also saw some functions used the processor's ticks and ticks per second to calculate the end result, which I think could be a problem on a CPU with auto-overclock like the one I have. I also saw one of them reset after a while, thus is not really reliable. The idea is to ma
我研究了几个主题,试图获得关于如何使用C或C ++制作可靠时钟的一些想法。 不过,我也看到一些函数使用处理器的刻度和每秒钟的刻度来计算最终结果,我认为这可能是一个像我拥有的自动超频的CPU问题。 我也看到其中一个在一段时间后重置,因此不是真的可靠。 我们的想法是制作一个(最好是跨平台的)时钟,就像游戏中的时钟一样,其精度优于一秒钟,以便能够在“当前会话”中添加已用时间并在最后保存时间的程序。 这将是计
I am very confused with one thing... If I add constructor to struct A then calculating in for loop becomes many times slower. Why? I have no idea. On my computer times of the snippet in outputs are: With constructor: 1351 Without constructor: 220 Here is a code: #include <iostream> #include <chrono> #include <cmath> using namespace std; using namespace std::chrono;
我非常困惑,有一件事......如果我将构造函数添加到结构A中,那么在for循环中计算会变慢很多倍。 为什么? 我不知道。 在我的电脑中输出片段的时间是: 带构造函数:1351 没有构造函数:220 这是一个代码: #include <iostream> #include <chrono> #include <cmath> using namespace std; using namespace std::chrono; const int SIZE = 1024 * 1024 * 32; using type = int; struct A { t
I'm not sure if the following code can cause redundant calculations, or is it compiler-specific? for (int i = 0; i < strlen(ss); ++i) { // blabla } Will strlen() be calculated every time when i increases? Yes, strlen() will be evaluated on each iteration. It's possible that, under ideal circumstances, the optimiser might be able to deduce that the value won't change, but I
我不确定下面的代码是否会导致冗余计算,还是编译器特定的? for (int i = 0; i < strlen(ss); ++i) { // blabla } 每次i增加时都会计算strlen()吗? 是的, strlen()将在每次迭代中被评估。 有可能在理想的情况下,优化器可能会推断出价值不会改变,但我个人不会依赖这一点。 我会做类似的事情 for (int i = 0, n = strlen(ss); i < n; ++i) 或可能 for (int i = 0; ss[i]; ++i) 只要字符串在迭代期间不会
I have a very simple problem that should have a simple answer as well, but so far no luck. I need to raise a double value to an array of integer powers, in c++ this would look something like for (int i = 0; i < N; ++i) { y[i] = pow(delta, l[i]); } But in Eigen I have tried a number of variants on this theme, without success. I have an Eigen::ArrayXi l_intE which maps an STL vector l_
我有一个非常简单的问题,应该有一个简单的答案,但到目前为止没有运气。 我需要将一个double值赋给一个整数幂的数组,在c ++中它看起来像这样 for (int i = 0; i < N; ++i) { y[i] = pow(delta, l[i]); } 但在Eigen中,我尝试了一些关于这个主题的变体,但没有成功。 我有一个映射STL向量l_int的Eigen::ArrayXi l_intE l_int 。 这不起作用: Eigen::pow(double, l_intE) 因为pow()函数需要一个数组作为第一个
In his book The C++ Standard Library (Second Edition) Nicolai Josuttis states that lambdas can be better optimized by the compiler than plain functions. In addition, C++ compilers optimize lambdas better than they do ordinary functions. (Page 213) Why is that? I thought when it comes to inlining there shouldn't be any difference any more. The only reason I could think of is that compi
在他的书The C++ Standard Library (Second Edition) Nicolai Josuttis指出,编译器可以比普通函数更好地优化lambda表达式。 另外,C ++编译器比普通函数更好地优化lambda表达式。 (页213) 这是为什么? 我认为当谈到内联时,应该没有任何区别了。 我能想到的唯一原因是编译器可能对lambda表达式有更好的本地环境,这样可以做出更多的假设并执行更多的优化。 原因是lambda是函数对象,因此将它们传递给函数模板将实
C++11 vectors have the new function emplace_back . Unlike push_back , which relies on compiler optimizations to avoid copies, emplace_back uses perfect forwarding to send the arguments directly to the constructor to create an object in-place. It seems to me that emplace_back does everything push_back can do, but some of the time it will do it better (but never worse). What reason do I have to
C ++ 11矢量具有新的函数emplace_back 。 与依靠编译器优化来避免副本的push_back不同, emplace_back使用完美转发将参数直接发送到构造函数以便就地创建对象。 在我看来, emplace_back所有push_back都可以做到的,但有些时候它会做得更好(但从不会更糟糕)。 我有什么理由使用push_back ? push_back总是允许使用统一的初始化,我非常喜欢它。 例如: struct aggregate { int foo; int bar; }; std::vector&l
I often find myself in a situation where I am facing multiple compilation/linker errors in a C++ project due to some bad design decisions (made by someone else :) ) which lead to circular dependencies between C++ classes in different header files (can happen also in the same file). But fortunately(?) this doesn't happen often enough for me to remember the solution to this problem for the nex
我经常发现自己处于C ++项目中由于一些糟糕的设计决定(由其他人制作)导致多个编译/链接器错误的情况,这导致了不同头文件中的C ++类之间的循环依赖关系(也可能发生在同一个文件中)。 但幸运的是(?)对于我下次再次发生这种问题时,这种情况通常不会发生。 因此,为了在未来轻松召回,我将发布代表性问题和解决方案。 更好的解决方案当然是受欢迎的。 Ah class B; class A { int _val; B *_b; public: A