FWRITE扼流圈"< XML版本" [英] fwrite chokes on "<?xml version"

查看:207
本文介绍了FWRITE扼流圈"< XML版本"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在字符串<?XML版本被写入通过fwrite的文件,后续的写操作变得更慢。

When the string <?xml version is written to a file via fwrite, the subsequent writing operations become slower.

这code:

#include <cstdio>
#include <ctime>
#include <iostream>

int main()
{
    const long index(15000000); 

    clock_t start_time(clock());
    FILE*  file_stream1 = fopen("test1.txt","wb");
    fwrite("<?xml version",1,13,file_stream1);
    for(auto i = 1;i < index ;++i)
        fwrite("only 6",1,6,file_stream1);
    fclose(file_stream1);

    std::cout << "\nOperation 1 took : " 
        << static_cast<double>(clock() - start_time)/CLOCKS_PER_SEC 
        << " seconds.";


    start_time = clock();
    FILE*  file_stream2 = fopen("test2.txt","wb");
    fwrite("<?xml versioX",1,13,file_stream2);
    for(auto i = 1;i < index ;++i)
        fwrite("only 6",1,6,file_stream2);
    fclose(file_stream2);

    std::cout << "\nOperation 2 took : " 
        << static_cast<double>(clock() - start_time)/CLOCKS_PER_SEC 
        << " seconds.";


    start_time = clock();
    FILE*  file_stream3 = fopen("test3.txt","w");
    const char test_str3[] = "<?xml versioX";
    for(auto i = 1;i < index ;++i)
        fwrite(test_str3,1,13,file_stream3);
    fclose(file_stream3);

    std::cout << "\nOperation 3 took : " 
        << static_cast<double>(clock() - start_time)/CLOCKS_PER_SEC 
        << " seconds.\n";

    return 0;
}

给我这样的结果:

Gives me this result :

Operation 1 took : 3.185 seconds.
Operation 2 took : 2.025 seconds.
Operation 3 took : 2.992 seconds.

这就是当我们替换字符串&LT; XML版本(操作1)&LT; XML versioX(操作2)其结果是显著更快。作为第一虽然它写入两次多个字符第三操作是一样快。

That is when we replace the string "<?xml version" (operation 1) with "<?xml versioX" (operation 2) the result is significantly faster. The third operation is as fast as the first though it's writing twice more characters.

任何人都可以重现此?

Windows 7中,32位,MSVC 2010

Windows 7, 32bit, MSVC 2010

修改1

在 -​​ [R ..建议,禁止微软Security Essentials的恢复正常的行为。

After R.. suggestion, disabling Microsoft Security Essentials restores normal behavior.

推荐答案

在Windows中,大多数(所有?)防病毒软件的工作原理是挂钩到读和/或写操作运行的数据文件中读取或重新写入病毒模式,并把它归类为安全或病毒。我怀疑你的防病毒软件,一旦它看到一个XML头,加载了XML恶意软件病毒码并从开始不断检查,看看如果你正在写磁盘的XML是一种已知病毒的一部分这一点。

On Windows, most (all?) anti-virus software works by hooking into the file read and/or write operations to run the data being read or written again virus patterns and classify it as safe or virus. I suspect your anti-virus software, once it sees an XML header, loads up the XML-malware virus patterns and from that point on starts constantly checking to see if the XML you're writing to disk is part of a known virus.

当然,这种行为是完全荒谬的,是什么让AV节目如此糟糕的名声与主管的用户,谁看到他们的表现,尽快为他们打开AV暴跌的一部分。同样的目标可以在不破坏性能的其它方式来实现。以下是他们应该使用一些想法:

Of course this behavior is utterly nonsensical and is part of what gives AV programs such a bad reputation with competent users, who see their performance plummet as soon as they turn on AV. The same goal could be accomplished in other ways that don't ruin performance. Here are some ideas they should be using:


  • 只有在写作和阅读之间的转换一次扫描文件,而不是之后每写。即使你没有写一个病毒到硬盘,它不会成为一个威胁,直到后来得到的阅读的一些过程。

  • 一旦文件被扫描时,请记住,它是安全的,不再次扫描它,直到它的修改。

  • 只扫描可执行程序或被检测为另一个程序正在使用的脚本/程序般的数据文件。

  • Only scan files once at transitions between writing and reading, not after every write. Even if you did write a virus to disk, it doesn't become a threat until it subsequently gets read by some process.
  • Once a file is scanned, remember that it's safe and don't scan it again until it's modified.
  • Only scan files that are executable programs or that are detected as being used as script/program-like data by another program.

不幸的是,我不知道有什么解决办法之前,杀毒软件厂商的聪明起来,除了把你的AV关闭...通常是在Windows上一个坏主意。

Unfortunately I don't know of any workaround until AV software makers wise up, other than turning your AV off... which is generally a bad idea on Windows.

这篇关于FWRITE扼流圈&QUOT;&LT; XML版本&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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