草庐IT

cpu-type

全部标签

c++ - 用 C++ 测量程序的 CPU 时间和挂钟时间

std::clock()测量程序持续时间内的时钟滴答数。在下面的代码中,它计算的是CPU时间还是挂钟时间?std::clock_t开始;双倍持续时间;start=std::clock();/*Youralgorithmhere*/duration=(std::clock()-start)/(double)CLOCKS_PER_SEC;另一种场景,代码如下:std::clock_tstart;doubletime;start=std::clock();time=start/(double)CLOCKS_PER_SEC;时间的值(value)是多少? 最佳答案

C++ : Different deduction of type auto between const int * and cont int &

这里是代码示例。a.intii=0;b.constintci=ii;c.autoe=&ci;-->eisconstint*d.auto&f=42;-->invalidinitializationofnon-constreferenceoftype‘int&’fromanrvalueoftype‘int’e.constauto&g=42-->ok观察:1.对于c)子句,自动推导类型const2.对于子句d),不会自动推导出类型const3.对于条款e),必须手动添加类型const才能使其工作。为什么子句c而不是d会自动推导类型const? 最佳答案

c++ - gcc/C++ : If CPU load is low, 那么代码优化没什么用,对吗?

我的同事喜欢使用带“-g-O0”的gcc来构建生产二进制文件,因为如果发生核心转储,调试很容易。他说不需要使用编译器优化或调整代码,因为他发现生产过程中的CPU负载不高,例如30%左右。我问他原因,他告诉我:如果CPU负载不高,瓶颈一定不是我们的代码性能,应该是一些IO(磁盘/网络)。因此,使用gcc-O2无法改善延迟和吞吐量。这也表明我们在代码中没有太多需要改进的地方,因为CPU不是瓶颈。对吗? 最佳答案 关于CPU使用~优化我希望程序中的大多数优化问题都与高于平常的CPU负载相关,因为我们说次优程序做的比理论上需要的多。但这里的

c++ - 循环依赖 : can't delete an incomplete type

我不明白为什么会出现此编译器错误:errorC2027:useofundefinedtype'GameState'note:seedeclarationof'GameState'errorC2338:can'tdeleteanincompletetypewarningC4150:deletionofpointertoincompletetype'GameState';nodestructorcalled这是相关代码:#pragmaonce#include#include"SpawnManager.h"#include"Resource.h"#include#includeclassGa

c++ - 转发声明/包含在模板类中 - "invalid use of incomplete type"

我正在尝试制作一个模板类,其中有一个函数接受该模板的特定实例。我做了以下人为的例子来说明这一点。比方说,我有一个标有模板化(通用)数据类型的个人世界。我有一个特定的个体,称为国王。所有个人都应该能够在国王面前下跪。一般来说,个人可以被标记为任何东西。国王用数字标记(第1、2位国王)。错误g++-g-O2-Wall-Wno-sign-compare-Iinclude-DHAVE_CONFIG_H-c-oIndividual.oIndividual.cppg++-g-O2-Wall-Wno-sign-compare-Iinclude-DHAVE_CONFIG_H-c-oKing.oKing

c++ - 为什么当我的应用程序最小化时 CPU 使用率会增加?

我正在编写一个计算器。当窗口最大化时,CPU占用率在12%左右,而当窗口最小化时,CPU占用率上升到50%左右。为什么会发生这种情况,我该如何防止这种情况发生?这是我认为导致问题的一段代码。LRESULTCALLBACKWndProc(HWNDhWnd,UINTuMsg,WPARAMwParam,LPARAMlParam){switch(uMsg){caseWM_ACTIVATE:if(!HIWORD(wParam))active=true;elseactive=false;return0;caseWM_SYSCOMMAND:switch(wParam){caseSC_SCREENSA

c++ - "member of type foo has private copy constructor"错误 : why's it an error?

我试图定义这样一个类:#includeclassmy_class{private:someone_elsesfoo;public:myclass();~myclass();//...};但是编译器失败了:“someone_elses类型的字段foo有一个私有(private)的复制构造函数”。现在我知道我可以通过以下方式解决这个问题:classmy_class{private:someone_elses*foo;//...};my_class::my_class(){foo=newsomeone_elses();}my_class::~my_class(){deletefoo;}我的问

c++ - 编译错误 : unresolved overloaded function type

我尝试用g++4.7.2编译以下内容:templatestructA{structB{Tt;templateTget(){returnthis->*M;}};Bb;Tget(){returnb.get();}};intmain(){Aa;a.get();}它给了我test.cpp:Inmemberfunction‘TA::get()’:test.cpp:15:23:error:expectedprimary-expressionbefore‘)’tokentest.cpp:Ininstantiationof‘TA::get()[withT=int]’:test.cpp:22:8:req

c++ - 如何从 boost::timer::cpu_timer 获取耗时(以秒为单位)?

以下粗略代码,基于thedocumentation,给我从boost中提供的计时器对象中耗时(以秒为单位)。boost::timer::cpu_timertimer;//...dosomework...constboost::timer::nanosecond_typeoneSecond(1000000000LL);returntimer.elapsed().user/oneSecond;这个方法的问题是我的代码中有这个令人不舒服的魔数(MagicNumber)。boost中是否有某种方法可以从nanosecond_type值中为我提供elapsed().user调用中可用的elaps

c++ - 错误 : aggregate 'first one' has incomplete type and cannot be defined

我写了这个头文件(header1.h):#ifndefHEADER1_H#defineHEADER1_Hclassfirst;//intsumm(inta,intb);#endif和这个源文件(header1.cpp和main.cpp):#include#include"header1.h"usingnamespacestd;classfirst{public:inta,b,c;intsum(inta,intb);};intfirst::sum(inta,intb){returna+b;}#include#include"header1.h"usingnamespacestd;firs