本文介绍了C ++很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下两个程序:


PROG I

void main()

{

int * v = new int [NUM];

for(int i = 0; i< NUM; ++ i)

v [i] = i ;

}


PROG II

class rvector

{

私人:

int * vals;

size_t vsize;


public:

显式rvector (size_t vSize){vals = new int [vsize]; }

~rvector(){delete [] vals; }


int& operator [](size_t idx){return vals [idx]; }

};


void main()

{

rvector v(NUM);

for(i = 0; i< NUM; ++ i)

v [i] = i;

}


我省略了一些非关联线,例如,定义NUM并包括标题

文件。


我编译并运行这些程序使用VC ++ 6.0。第二个程序

所需的时间约为第一个的6倍。发生了什么

在程序II中花了那么多时间?


-charles

I have the following two programs:

PROG I
void main()
{
int *v = new int[NUM];
for (int i = 0; i < NUM; ++i)
v[i] = i;
}

PROG II
class rvector
{
private:
int* vals;
size_t vsize;

public:
explicit rvector( size_t vSize ) { vals = new int[vsize]; }
~rvector() { delete [] vals; }

int& operator[] (size_t idx ) { return vals[idx]; }
};

void main()
{
rvector v(NUM);
for (i = 0; i < NUM; ++i)
v[i] = i;
}

I left out some non-germane lines, eg, defining NUM and including header
files.

I compiled and ran these programs using VC++ 6.0. The second program
required approx 6 times as much time to run as the first. What is happening
in program II that takes so much time?

-charles

推荐答案





C ++语言是一组规范,一个抽象。

我没有'速度',慢或快。显然你发现C ++的特定的实现*(VC ++ 6.0)太慢。


推荐的行动:


阅读您的文档以确保您正确使用该产品,

并找到它的各种模式操作。


如果VC ++被认为是不可接受的,请使用别的东西。


-Mike



The C++ language is a set of specifications, an abstraction.
I has no ''speed'', slow or fast. Apparently you find a particular
*implementation* of C++, (VC++6.0) "too slow".

Recommended actions:

Read your documentation to ensure you''re using the product correctly,
and find it''s various ''modes'' of operation.

If VC++ is deemed unacceptable, use something else.

-Mike



这篇关于C ++很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 04:15