<bdo id='LFQBB'></bdo><ul id='LFQBB'></ul>
  1. <i id='LFQBB'><tr id='LFQBB'><dt id='LFQBB'><q id='LFQBB'><span id='LFQBB'><b id='LFQBB'><form id='LFQBB'><ins id='LFQBB'></ins><ul id='LFQBB'></ul><sub id='LFQBB'></sub></form><legend id='LFQBB'></legend><bdo id='LFQBB'><pre id='LFQBB'><center id='LFQBB'></center></pre></bdo></b><th id='LFQBB'></th></span></q></dt></tr></i><div id='LFQBB'><tfoot id='LFQBB'></tfoot><dl id='LFQBB'><fieldset id='LFQBB'></fieldset></dl></div>
  2. <tfoot id='LFQBB'></tfoot>

      <small id='LFQBB'></small><noframes id='LFQBB'>

      <legend id='LFQBB'><style id='LFQBB'><dir id='LFQBB'><q id='LFQBB'></q></dir></style></legend>
    1. 为什么当我连接了调试器/IDE 时,我的 STL 代码运行得如此缓慢?

      Why does my STL code run so slowly when I have the debugger/IDE attached?(为什么当我连接了调试器/IDE 时,我的 STL 代码运行得如此缓慢?)
      <legend id='DZJSB'><style id='DZJSB'><dir id='DZJSB'><q id='DZJSB'></q></dir></style></legend>
        <tfoot id='DZJSB'></tfoot>

        <small id='DZJSB'></small><noframes id='DZJSB'>

            <bdo id='DZJSB'></bdo><ul id='DZJSB'></ul>

          • <i id='DZJSB'><tr id='DZJSB'><dt id='DZJSB'><q id='DZJSB'><span id='DZJSB'><b id='DZJSB'><form id='DZJSB'><ins id='DZJSB'></ins><ul id='DZJSB'></ul><sub id='DZJSB'></sub></form><legend id='DZJSB'></legend><bdo id='DZJSB'><pre id='DZJSB'><center id='DZJSB'></center></pre></bdo></b><th id='DZJSB'></th></span></q></dt></tr></i><div id='DZJSB'><tfoot id='DZJSB'></tfoot><dl id='DZJSB'><fieldset id='DZJSB'></fieldset></dl></div>

                  <tbody id='DZJSB'></tbody>
                本文介绍了为什么当我连接了调试器/IDE 时,我的 STL 代码运行得如此缓慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在运行以下代码,使用 Visual Studio 2008 SP1,在 Windows Vista Business x64、四核机器、8gb 内存上.

                I'm running the following code, using Visual Studio 2008 SP1, on Windows Vista Business x64, quad core machine, 8gb ram.

                如果我构建了一个发布版本,并从命令行运行它,它会报告 31 毫秒.如果我然后从 IDE 启动它,使用 F5,它会报告 23353 毫秒.

                If I build a release build, and run it from the command line, it reports 31ms. If I then start it from the IDE, using F5, it reports 23353ms.

                时间如下:(所有 Win32 版本)

                Here are the times: (all Win32 builds)

                • 调试,命令行:421 毫秒
                • 从 IDE 调试:24,570 毫秒
                • 释放,命令行:31 毫秒
                • 从 IDE 中释放:23,353 毫秒

                代码:

                #include <windows.h>
                #include <iostream>
                
                #include <set>
                #include <algorithm>
                using namespace std;
                
                int runIntersectionTestAlgo()
                {   
                
                    set<int> set1;
                    set<int> set2;
                    set<int> intersection;
                
                
                    // Create 100,000 values for set1
                    for ( int i = 0; i < 100000; i++ )
                    {
                        int value = 1000000000 + i;
                        set1.insert(value);
                    }
                
                    // Create 1,000 values for set2
                    for ( int i = 0; i < 1000; i++ )
                    {
                        int random = rand() % 200000 + 1;
                        random *= 10;
                
                        int value = 1000000000 + random;
                        set2.insert(value);
                    }
                
                    set_intersection(set1.begin(),set1.end(), set2.begin(), set2.end(), inserter(intersection, intersection.end()));
                
                    return intersection.size(); 
                }
                
                int main(){
                    DWORD start = GetTickCount();
                
                    runIntersectionTestAlgo();
                
                    DWORD span = GetTickCount() - start;
                
                    std::cout << span << " milliseconds
                ";
                }
                

                推荐答案

                默认情况下在 Microsoft 调试器(windbg、kd、cdb、Visual Studio 调试器)下运行会强制 Windows 使用调试堆而不是默认堆.在 Windows 2000 及更高版本上,默认堆是 Low Fragmentation Heap,与调试堆相比,这是非常好的.您可以使用 HeapQueryInformation.

                Running under a Microsoft debugger (windbg, kd, cdb, Visual Studio Debugger) by default forces Windows to use the debug heap instead of the default heap. On Windows 2000 and above, the default heap is the Low Fragmentation Heap, which is insanely good compared to the debug heap. You can query the kind of heap you are using with HeapQueryInformation.

                要解决您的特定问题,您可以使用此知识库文章中推荐的众多选项之一:为什么某些运行 Windows Server 2003、Windows XP 或 Windows 2000 的计算机可能会禁用低碎片堆 (LFH) 机制

                To solve your particular problem, you can use one of the many options recommended in this KB article: Why the low fragmentation heap (LFH) mechanism may be disabled on some computers that are running Windows Server 2003, Windows XP, or Windows 2000

                对于 Visual Studio,我更喜欢将 _NO_DEBUG_HEAP=1 添加到 Project Properties->Configuration Properties->Debugging->Environment.这对我来说总是有用的.

                For Visual Studio, I prefer adding _NO_DEBUG_HEAP=1 to Project Properties->Configuration Properties->Debugging->Environment. That always does the trick for me.

                这篇关于为什么当我连接了调试器/IDE 时,我的 STL 代码运行得如此缓慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                Adding types to the std namespace(将类型添加到 std 命名空间)
                Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)
              • <tfoot id='M19yD'></tfoot>

                <i id='M19yD'><tr id='M19yD'><dt id='M19yD'><q id='M19yD'><span id='M19yD'><b id='M19yD'><form id='M19yD'><ins id='M19yD'></ins><ul id='M19yD'></ul><sub id='M19yD'></sub></form><legend id='M19yD'></legend><bdo id='M19yD'><pre id='M19yD'><center id='M19yD'></center></pre></bdo></b><th id='M19yD'></th></span></q></dt></tr></i><div id='M19yD'><tfoot id='M19yD'></tfoot><dl id='M19yD'><fieldset id='M19yD'></fieldset></dl></div>
                  <bdo id='M19yD'></bdo><ul id='M19yD'></ul>

                  <small id='M19yD'></small><noframes id='M19yD'>

                          <tbody id='M19yD'></tbody>

                          <legend id='M19yD'><style id='M19yD'><dir id='M19yD'><q id='M19yD'></q></dir></style></legend>