×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / 各位编程高手请进,谢谢。
    请问用VC++编程时,如果用到new来进行内存的分配,是否特别影响执行速度。我程序中的数组原先是30*30的,不用内存分配即可执行。可现在改成80*80的,就必须要用到内存分配,否则出错。原先运行程序只需要40多秒,可现在居然要一个半小时,太夸张了吧。请问会有这么大的差距吗?另外,如何能够提高执行的速度,恢复到原来的水平?谢谢。
    • up and help please!!
    • did you try C language? If the problem still exsits, you should check your algorithm
    • 什么类型的数组? 多半是算法问题,有否递归处理在你的程序中?
      • read it in 论坛热点区 I dont have good answer for that question
        • 你真的很帮忙了,衷心感谢你。check your mail.
      • 你的高见,谢谢了。具体情况见内。我的一个朋友说已经没办法简化算法了。
        首先s1,s2是80*80的数组。inputN1=80,beita=0.3,其余均为变量
        需要计算的公式是:
        s2[p][q]=max(max(w(p-i,q-j)*s1[i][j]))
        p,q,i,j from 0 to 79
        w(m,n)=exp(-beita*(m^2+n^2))
        m,n from -79 to 79

        程序如下,已经进行了简化。
        真正的计算是从第20行开始,前面都是为了简化计算。
        我想问题就出在这里,我试着把这段程序用s2[i][j]=s1[i][j]代替,速度巨快。
        不知道有什么办法能够优化这段程序呢?请一定赐教。谢谢。

        1 NN=40;
        2 for (i=0;i<inputN1;i=i+1)
        3 {
        4 for (j=0;j<inputN1;j=j+1)
        5 {
        6 nb1=j-NN;
        7 if (nb1<0)
        8 nb1=0;
        9 nb2=j+NN;
        10 if (nb2>inputN1)
        11 nb2=inputN1;
        12
        13 nb3=i-NN;
        14 if (nb3<0)
        15 nb3=0;
        16 nb4=i+NN;
        17 if (nb4>inputN1)
        18 nb4=inputN1;
        19
        20 aa=0;
        21 for (i1=nb3;i1<nb4;i1=i1+1)
        22 {
        23 for (j1=nb1;j1<nb2;j1=j1+1)
        24 {
        25 j2=abs(i-i1);
        26 j3=abs(j-j1);
        27 fai=exp(-beita*(j2*j2+j3*j3));
        28 bb=fai*s1[i1][j1];
        29 if(aa<bb) aa=bb;
        30 }
        31 }
        32 s2[i][j]=aa;
        33 }
        34 }
        • I could do better if I knew what the issue is. Please read new source codes inside.
          N1 = 80;
          beita = 0.3;

          // s3[N1][N1]
          for(i = 0; i < N1; i++)
          for(j = i; j < N1; j++)
          s3[i][j] = s3[j][i] = exp(-beita * (i * i + j * j));

          NN = 40;

          nb3 = 0;
          nb4 = NN - 1;
          for(i = 0; i < N1; i++)
          {
          if(i > NN)
          nb3++;

          if(nb4 < N1)
          nb4++;

          nb1 = 0;
          nb2 = NN - 1;
          for(j = 0; j < N1; j++)
          {
          if(j > NN)
          nb1++;

          if(nb2 < N1)
          nb2++;

          aa = 0;
          for(i1 = nb3; i1 < nb4; i1++)
          {
          for (j1 = nb1; j1 < nb2; j1++)
          {
          j2 = i > i1 ? i - i1 : i1 - i;
          j3 = j > j1 ? j - j1 : j1 - j;

          bb = s3[j2][j3] * s1[i1][j1];
          if(aa < bb)
          aa = bb;
          }
          }

          s2[i][j] = aa;
          }
          }
          • Thank you for your help.You are really so kind!!!!!!!!!
            • wow, try this way check if the link exist /dev/diskette, or /dev/diskette0, this should point to /device/.... If the link looks ok, rm the file in /device... and 'reboot -- -r'. If null link, the floppy drive is bad.
              • ?????
              • sorry, bug?! I was supposed to reply the topic below