除非编译“明显"缓慢,否则编译后的首次执行会非常缓慢.所有循环都将停止 [英] First execution after compiling incredibly slow, unless it's "obvious" that all loops will halt

查看:58
本文介绍了除非编译“明显"缓慢,否则编译后的首次执行会非常缓慢.所有循环都将停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个标题的意思是,在某些情况下,在构建整个程序之后,它的第一次执行将花费大约25秒钟的时间(直到控制台上的第一个printf显示).下一次执行几乎立即开始(如应执行).添加/删除空间并再次编译,之后的第一次执行又变得异常缓慢.

What I meant with this title is that for some cases, after building the entire program, its first execution will take about 25 seconds to start (until the first printf shows on the console). The next executions start nearly instantaneously (as they should). Add/remove a space and compile again, and the first execution after is once again excruciatingly slow.

天气我可以在IDE(代码:: Blocks)中运行,也可以从文件资源管理器中运行.

Weather I run it from within the IDE (Code::Blocks) or from the file explorer changes nothing.

但这是解决"问题的方法:

But here's what "solves" the problem:

我编写的程序有一个循环,并且一直在等待用户输入:

The program I wrote has a cycle and it's constantly waiting for user input:

#include <stdio.h>
#include <string>

using namespace std;

int main()
{
    printf("Welcome!\n");

    bool Running=true;

    do{

      char input[256], command[64];


      if(fgets(input, 256, stdin) == NULL || input[0]=='\n')
        continue;

      sscanf(input, "%s", command);

      string command_cppstr(command);

      if(command_cppstr == "help")
      {
        printf("\n");
        printf("help - displays this list\n");
        printf("exit / quit - exits this progam\n\n");
        continue;
      }
      if(command_cppstr == "exit" || command_cppstr == "quit")
      {
        Running = false;
        continue;
      }

      printf("Unrecognized command. Use command \"help\" for a list of commands and their descriptions.\n");

    }while(Running);

    return 0;
}

该程序具有前面提到的问题.但是,如果我做很多事情来保证程序将停止运行,该问题将不再发生.例如,声明如下:

This program has the issues mentioned before. But if I do any of a number of things that guarantee that the program will halt, the problem no longer occurs. For example, declaring this:

int i=0;

,然后在do while循环中插入以下内容:

and inserting the following inside the do while loop:

i++;
if(i>4)
  Running=false;

不仅使程序在处理完4条命令后停止运行,而且还解决"了问题-.exe不再需要永恒的时间才能第一次执行.我将解决"放在两个逗号之间,因为我只想在用户说出退出"或退出"命令时暂停程序.

not only makes the program stop after 4 commands have been processed, it also "solves" the problem - the .exe no longer takes an eternity to execute the first time. I put "solves" between inverted commas because I only wanted my program to halt when the user says so by typing the command "quit" or "exit".

我再次注意到我先编译,等到所有内容都编译好后,再运行可执行文件.

I once again note that I compile first, wait until everything is compiled, and only then do I run the executable.

我想知道如何避免这种情况,因为即使我找到了部分解决方案,它也不是我理想的选择.我也想知道是什么原因导致了这个问题.就像计算机不愿运行可能永远不会停止的代码一样,担心陷入无限循环的xD中.

I would like to know how do I avoid this, because even though I have found a partial solution, it's not exactly ideal to me. I would also like to know what causes this problem. It's as if the computer was reluctant in running code that may never halt, fearing being caught in an endless loop xD.

感谢您对这篇文章的关注,并在此先感谢所有尝试回答这些问题的人.

Thank you for your attention to this post, and thank you in advance to anyone who attempts to answer these questions.

好吧,这是我到目前为止阅读答案后尝试过的事情:

Ok, here's what I tried so far, after reading the answers:

  • 禁用卡巴斯基(我的防病毒软件)-问题消失了.但这不是一个好的解决方案,因为我不喜欢没有防病毒软件的想法.

我重新激活了卡巴斯基:

I reactivated Kaspersky:

  • 取消选中使用启发式分析可以确定未知应用的[限制]组-无效
  • 禁用卡巴斯基的应用程序控制"-无效
  • 禁用卡巴斯基的系统监视"-无效
  • 禁用卡巴斯基的"Antiviros de MI"(似乎是聊天室相关的内容)-无效
  • 在漏洞验证设置"中禁用验证范围"-无效
  • 在卡巴斯基的应用程序控件中赋予程序可信任状态-无效
  • 将该程序放在卡巴斯基的卡巴斯基排除列表中-无效
  • 在卡巴斯基的卡巴斯基排除列表中输入代码:::阻止-无效

在卡巴斯基,有很多事情可以禁用,但是我认为我尝试过的事情最有可能影响这种情况.但这一定是卡巴斯基的错,因为禁用它可以解决问题.我想我会尝试禁用更多功能...

There are a lot of things that can be disabled in Kaspersky, but I think the ones I tried are the most likely to affect this situation. But it must be Kaspersky's fault, since disabling it solved the problem. I guess I'll try disabling more things...

我还尝试了以下方法:

  • 用我声明的功能交换i ++(我通过引用和增量传递)-无需等待
  • 用我声明的函数交换i ++(函数返回参数+1)-无需等待
  • i从1开始,在每个循环中乘以2.当它大于8时,Running = false-无需等待
  • i从0开始,在每个循环中乘以2.当它大于8时,Running = false-等待(因为这不能保证xD会停止)

我将继续尝试改变增加i的方式,以尝试进一步消除似乎正在检查我的程序是否停止xD的任何事情……在进行实验时,我将使用结果对其进行编辑.

I will continue to try to change the way i is increased to try to further throw off whatever thing appears to be checking if my program halts or not xD... I will edit this with the results as I make the experiments.

我继续尝试在卡巴斯基找到可以解决此问题的方法

I continued trying to find what I could do in Kaspersky that would solve this problem

显然,禁用防火墙和应用程序控制"功能可以解决此问题.我想让计算机在没有防火墙的情况下运行并不是什么好事.

Apparently, disabling the firewall and the "App control" features solves the problem. But it's not a very good deal to have the computer running without a firewall, I thought.

所以我重新启用了这两个功能,并且在应用程序控制"中,有一个未知应用程序"选项,

So I re-enabled both of these functions, and in "App control" there's an option for "unknown apps", between

  • 使用启发式分析来确定组(即信任度").
  • 自动将应用程序分为以下几类:[您可以在其中选择3个值得信赖的组的框]

,然后有一个框显示:

确定组的最长时间:< _>秒.

maximum time to determine group: <_> seconds.

现在这是有趣的部分:此框中的秒数与程序开始运行之前所花费的时间直接相关.(此时间永远不会大于秒数+〜2)

Now here's the interesting part: The amount of seconds in this box is directly related to the time it takes before a program starts running. (this time is never greater than the amount of seconds + ~2)

但谜团还没有结束:

当我停用启发式分析功能时,这最后一行显示为灰色,并且测试框也被禁用,这表明禁用启发式分析后,就无需等待了.但是还有!而且它仍然与插入到现在不可编辑的文本框中的时间有关!

This last line gets grayed out, and the test box gets disabled when I deactivate the heuristic analysis thing, which would suggest that when heuristic analysis is disabled, there would be no waiting. But there is! And it's still related to the time that is inserted to the now un-editable text box!

哦,为什么防火墙的状态根本不重要?据说,必须完全停用应用程序控制"才能解决此问题,但不是,必须同时禁用防火墙和应用程序控制!

Oh, and why would the state of the firewall matter at all? Supposedly, deactivating "app control" would be all took for this problem to go away, but no, both the firewall and the app control have to be disabled!

推荐答案

乍一看,它看起来像杀毒软件.每次看到新的可执行文件正在运行时,它都会检查文件中是否存在病毒.每当您重新编译时,它都必须再次检查文件,因为它已更改.

At first sight this looks like antivirus software. Every time it sees a new executable file being run, it checks the file for viruses. Whenever you recompile, it has to check the file again, because it's changed.

但是您对问题的解决方案"让我感到困惑!您所描述的似乎是不可能的.程序(或OS或防病毒软件)如何知道循环数受到限制?我认为这里需要进行进一步的实验.

But your "solution" to the problem has me baffled! What you describe seems impossible. How can the program (or the OS, or the antivirus software) know that the number of loops is limited? I think further experimentation is in order here.

首先,您可以尝试将可执行文件添加到防病毒软件的排除列表中.会发生什么?

As a start, you might try adding the executable file to your antivirus software's exclude list. What happens?

这篇关于除非编译“明显"缓慢,否则编译后的首次执行会非常缓慢.所有循环都将停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆