This topic has been archived. It cannot be replied.
-
工作学习 / IT杂谈 / 请问用VC++编程时,如果用到new来进行内存的分配,是否特别影响执行速度。我程序中的数组原先是30*30的,不用内存分配即可执行。可现在改成80*80的,就必须要用到内存分配,否则出错。原先运行程序只需要40多秒,可现在居然要一个半小时,太夸张了吧。请问会有这么大的差距吗?另外,如何能够提高执行的速度,恢复到原来的水平?谢谢。
-guest:;
2001-8-30
{170}
(#184643@0)
-
你去chinasmile发巴, 我在这里不回答任何技术问题,
-guest:;
2001-8-30
(#184653@0)
-
你的内存不够了吧. 既然直接执行出错,改用分配内存就可以了, 很可能是你的内存没有80*80个元素那么多. 改用分配内存后,大概是由于运算的需要, 数据在内存与硬盘之间换来换去,就会慢.如果是这样, 试试优化你的算法, 争取某些数据运算过之后就不需要再读了.
-zjoy(Joy);
2001-8-30
{67}
(#184656@0)
-
thanks.
-guest:;
2001-8-30
(#184664@0)
-
you should compare 30*30 with/without using new/delete first.
-scorpio(scorpio);
2001-8-30
(#184718@0)
-
what do you mean? when I use 30*30, it doesn\
-guest:;
2001-8-30
(#184754@0)
-
what do you mean?When I used 30*30,it doesn\
-guest:;
2001-8-30
{10}
(#184758@0)
-
sorry, there is something wrong with my computer. I mean when I used 30*30, it ok. But when it change to be 80*80, it can\
-guest:;
2001-8-30
(#184762@0)
-
如果你想要知道是不是new/delete让你的速度降低,你得用new申请30*30的内存的速度和直接用数组的速度比吧,还不然没法比压。
-scorpio(scorpio);
2001-8-30
(#184818@0)
-
I tried and it\
-guest:;
2001-8-30
(#185006@0)
-
It\
-guest:;
2001-8-30
(#185007@0)
-
it's ok with30*30.
-guest:;
2001-8-30
(#185018@0)
-
what you mean of "it is ok"
-scorpio(scorpio);
2001-8-30
(#185039@0)
-
that means the speed is the same as before(not adding new/delete).Please help me.. What can I do now?
-guest:;
2001-8-30
(#185042@0)
-
so this problem has nothing to do with new/delete, it comes from your algorithm. use some analysis tools to check which function take most of the time, change it.
-scorpio(scorpio);
2001-8-30
(#185052@0)
-
how about add some memory into my computer?
-guest:;
2001-8-30
(#185060@0)
-
sure. It'll help. But keep in mind that your new 80*80 is about 7 times of 30*30. Try to increase the dimension gradually to find out about how much memory you need.
-zjoy(Joy);
2001-8-30
(#185067@0)
-
80*80 = 6.4k... 我怎么觉得6.4k的数组可以直接声明的压。上限不是64k吗?
你的时间变长和NEW没关系,如果用VC,选ENABLE PROFILE,看看各个函数占的时间再说。
-scorpio(scorpio);
2001-8-30
(#185079@0)
-
我也觉得和NEW本身没关系. 好像也不是声明的问题吧.不知道他的每个元素有多大? 如果每个元素占10BYTES, 整个数组要用64K MEMORY.
-zjoy(Joy);
2001-8-30
(#185088@0)
-
How toselect Enable Profile. Where?Thanks
-guest:;
2001-8-30
(#185160@0)
-
scorpio,请看这里。事实上,我用的数组是80*80*372,请问什么是enable profile?我的程序中只有两个四层循环非常占用时间,别的都没什么。
-guest:;
2001-8-30
(#185085@0)
-
do u mind to post ur source code here?
-scorpio(scorpio);
2001-8-30
(#185117@0)