我试图比较内联汇编语言和C++代码的性能,所以我写了一个函数,添加两个大小为2000的数组,持续100000次.这是代码:
#define TIMES 100000
void calcuC(int *x,int *y,int length)
{
for(int i = 0; i < TIMES; i++)
{
for(int j = 0; j < length; j++)
x[j] += y[j];
}
}
void calcuAsm(int *x,int *y,int lengthOfArray)
{
__asm
{
mov edi,TIMES
start:
mov esi,0
mov ecx,lengthOfArray
label:
mov edx,x
push edx
mov eax,DWORD PTR [edx + esi*4]
mov edx,y
mov ebx,DWORD PTR [edx + esi*4]
add eax,ebx
pop edx
mov [edx + esi*4],eax
inc esi
loop label
dec edi …
Run Code Online (Sandbox Code Playgroud) 我尝试在某些操作中显示进度条.但是,我不知道需要多少次才能计算百分比.Windows似乎有这样的进度条样式:
我尝试通过将maximum和minimum设置为0来实现此样式:
ui->progressBar->setMaximum(0);
ui->progressBar->setMinimum(0);
Run Code Online (Sandbox Code Playgroud)
似乎我做了它,除了它确实不会停止,直到程序退出,尽管我调用reset()函数试图阻止它.
所以我的问题是如何正确实现这种进度条?
我试图序列化一个矢量和一个地图容器,并通过cout输出它们的值.但是,我很难理解boost的输出含义.我的代码看起来像这样:
#include <iostream>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
#include <boost/assign.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <sstream>
#include <fstream>
using namespace std;
int main()
{
vector<int> v = boost::assign::list_of(1)(3)(5);
map<int, string> m = boost::assign::map_list_of(1,"one")(2,"two");
std::stringstream ss;
boost::archive::text_oarchive oa(ss);
oa<<v<<m;
vector<int> v_;
map<int,string> m_;
boost::archive::text_iarchive ia(ss);
ia>>v_>>m_;
boost::archive::text_oarchive ib(cout);
ib<<v_<<m_;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
22 serialization::archive 9 3 0 1 3 5 0 0 2 0 0 0 1 3 one 2 3 two
Run Code Online (Sandbox Code Playgroud)
在我创造的值1 3 5之前,数字9 3 0的含义是什么?0 0 2 0 0 …
我正在尝试将序列化集成到我的代码中.但是,我得到了一个'没有成员命名'的错误.我正在阅读的书中说std :: pair不需要包含头文件而且不存在.如何解决这个错误?我的代码看起来像这样:
#include <iostream>
//ofstream/ifstream
#include <fstream>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
//stringstream
#include <sstream>
//
#include <boost/serialization/complex.hpp>
#include <boost/serialization/bitset.hpp>
//#include <boost/serialization/
//BOOST_BINARY
#include <boost/utility/binary.hpp>
using namespace std;
int main()
{
complex<double> c(1,0);
bitset<3> b(BOOST_BINARY(101));
pair<int,int> p(1,2);
string s;
std::stringstream ss(s);
boost::archive::text_oarchive oa(ss);
oa<<c<<b<<p;
{
complex<double> c;
bitset<3> b;
pair<int,int> p;
boost::archive::text_iarchive ia(ss);
ia>>c>>b>>p;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我是OpenGL和Glut的新手.Glut实施了一个项目.我用Google搜索并发现Qt中有一个名为QGLWidget的OpenGL实现.但是,我很难将旧的Glut代码转换为新的Qt代码,因为我不知道如何在Qt中找到Glut函数的等效函数.部分代码如下所示:
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(gray1->width,gray1->height);
glutInitWindowPosition(100,100);
glutCreateWindow("hello");
init();
glutDisplayFunc(&display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMotionFunc(mouse_move);
glutMainLoop();
Run Code Online (Sandbox Code Playgroud)
Qt的文档中不存在上述过剩函数.所以我的问题是如何在QGLWidget的函数中找到等效的glut函数?