- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试用 C++ 重新创建 Windows Reg.exe 实用程序。具体来说,在 REG.exe 中完成以下命令所带来的功能。
REG QUERY "HKLM\Software" /s
但是,当我将结果输出到屏幕时,我似乎遇到了严重的瓶颈。
如果我注释掉 std::wcout << fPath.c_str()
, 该程序在 1.45 分钟内完成,而不是在 20 多分钟内完成评论。
我想知道为什么会这样,我该如何解决。
inline void show(HKEY aHkey, std::wstring aHkeyPath, std::wstring aSubKey, RegValue &aValueData, bool aDisplayPath, bool aDisplayValue, bool aLastItem)
{
if (aDisplayValue)
{
// Show registry value name
std::wstring lValueName = (aValueData.lValueName);
if (lValueName == TEXT("")) lValueName = TEXT("(Default)");
// Recover from non ascii characters
if (!std::wcout.good())
{
std::wcout.clear();
}
// Show registry type
std::wstring lDataType = convertToWstr(getDataTypeStringName(aValueData.lRegType));
std::wstring lDataValue;
// Show registry data
if (lDataType == L"REG_DWORD" ||
lDataType == L"REG_QWORD" ||
lDataType == L"REG_DWORD_LITTLE_ENDIAN" ||
lDataType == L"REG_QWORD_LITTLE_ENDIAN" ||
lDataType == L"REG_DWORD_BIG_ENDIAN")
{
lDataValue = L"0x0" + (aValueData.lDataValue);
}
else
{
lDataValue = (aValueData.lDataValue);
}
std::wstring fPath = lValueName + L" " + lDataType + L" " + lDataValue;
std::wcout << fPath.c_str();
}
std::cout << "\n";
}
注册值结构
struct RegValue
{
std::wstring lValueName;
unsigned int lRegType;
std::wstring lDataValue;
};
主体调用函数
RegValue lRegValueData;
std::wstring lCurrentSubKey = L"";
std::wstring lCurrentValue = L"";
unsigned int lMatchTotal = 0;
// HACK: Makes sure that lSubKeyList loop will be entered even if there is no sub keys
// Additionally, allows for the last subkey within the dequeue to be shown
lSubKeyList.push_back(L"End");
while (lSubKeyList.size())
{
//show(hkey, lHkeyPath, lCurrentSubKey, lRegValueData, true, false, false);
while (lValueList.size())
{
lCurrentValue = lValueList.front();
lValueList.pop();
lResult = getValueData(hkey, lHkeyPath, lCurrentSubKey, lCurrentValue, lRegValueData);
if (lResult != ERROR_SUCCESS)
{
error(lResult);
return false;
}
if (lFind || lFilterDataType)
{
bool lMatch = isMatch(lRegValueData, aVal.lDataType, lSearchParam);
if (lMatch)
{
show(hkey, lHkeyPath, lCurrentSubKey, lRegValueData, false, true, false);
lMatchTotal++;
}
}
else
{
show(hkey, lHkeyPath, lCurrentSubKey, lRegValueData, false, true, false);
}
//Create a space after last data value
if (lValueList.size() == 0 && !lSearchRecursive)
{
std::cout << "\n";
}
}
// Remove visted Sub-Key from deque
lCurrentSubKey = lSubKeyList.front();
lSubKeyList.pop_front();
if (lSearchRecursive && lCurrentSubKey != L"End")
{
//Create a space after the first key.
std::cout << "\n";
// If the parent key contains sub-keys, add them to lSubKeyList,
// in the order they were retrieved from RegEnumEx.
std::deque<std::wstring> lTemp;
lResult = getSubKeyList(hkey, lHkeyPath, lCurrentSubKey, lTemp);
while (lTemp.size())
{
lSubKeyList.push_front(lTemp.back());
lTemp.pop_back();
}
// A non-error. Error: "Invalid Handle"
// This error code just states that the current key being accessed
// does not contain any sub-keys.
if (lResult == 6) lResult = 0;
if (lResult != ERROR_SUCCESS)
{
error(lResult);
return false;
}
// Get the current keys value names
lResult = getValueNameList(hkey, lHkeyPath, lCurrentSubKey, lValueList);
// Ignore key values that cannot be accessed. Error "Access Denied"
// Keys cannot be accessed in regedit (admin), so this is a UAC issue.
if (lResult == 5) lResult = 0;
if (lResult != ERROR_SUCCESS)
{
error(lResult);
return false;
}
}
}
反汇编代码 (std::wcout << fPath.c_str())
std::wcout << fPath.c_str();
00007FF67E5759E3 lea rdx,[rbp]
00007FF67E5759E7 cmp qword ptr [rbp+18h],8
00007FF67E5759EC cmovae rdx,qword ptr [rbp]
00007FF67E5759F1 mov rcx,qword ptr [__imp_std::wcout (07FF67E57D140h)]
00007FF67E5759F8 call std::operator<<<wchar_t,std::char_traits<wchar_t> > (07FF67E577CE0h)
00007FF67E5759FD nop
}
00007FF67E5759FE mov rax,qword ptr [rbp+18h]
00007FF67E575A02 cmp rax,8
00007FF67E575A06 jb show+4B8h (07FF67E575A68h)
00007FF67E575A08 inc rax
00007FF67E575A0B mov rcx,qword ptr [rbp]
00007FF67E575A0F cmp rax,r13
00007FF67E575A12 jbe show+46Bh (07FF67E575A1Bh)
00007FF67E575A14 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575A1A int 3
00007FF67E575A1B add rax,rax
00007FF67E575A1E cmp rax,1000h
00007FF67E575A24 jb show+4B3h (07FF67E575A63h)
00007FF67E575A26 test byte ptr [rbp],1Fh
00007FF67E575A2A je show+483h (07FF67E575A33h)
00007FF67E575A2C call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575A32 int 3
00007FF67E575A33 mov rax,qword ptr [rcx-8]
00007FF67E575A37 cmp rax,rcx
00007FF67E575A3A jb show+493h (07FF67E575A43h)
00007FF67E575A3C call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575A42 int 3
00007FF67E575A43 sub rcx,rax
00007FF67E575A46 cmp rcx,8
00007FF67E575A4A jae show+4A3h (07FF67E575A53h)
00007FF67E575A4C call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575A52 int 3
00007FF67E575A53 cmp rcx,27h
00007FF67E575A57 jbe show+4B0h (07FF67E575A60h)
00007FF67E575A59 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575A5F int 3
00007FF67E575A60 mov rcx,rax
00007FF67E575A63 call operator delete (07FF67E57B430h)
00007FF67E575A68 mov qword ptr [rbp+18h],7
00007FF67E575A70 mov qword ptr [rbp+10h],r12
00007FF67E575A74 mov word ptr [rbp],r12w
00007FF67E575A79 mov rax,qword ptr [rbp-28h]
00007FF67E575A7D cmp rax,8
00007FF67E575A81 jb show+533h (07FF67E575AE3h)
00007FF67E575A83 inc rax
00007FF67E575A86 mov rcx,qword ptr [rbp-40h]
00007FF67E575A8A cmp rax,r13
00007FF67E575A8D jbe show+4E6h (07FF67E575A96h)
00007FF67E575A8F call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575A95 int 3
00007FF67E575A96 add rax,rax
00007FF67E575A99 cmp rax,1000h
00007FF67E575A9F jb show+52Eh (07FF67E575ADEh)
00007FF67E575AA1 test byte ptr [rbp-40h],1Fh
00007FF67E575AA5 je show+4FEh (07FF67E575AAEh)
00007FF67E575AA7 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575AAD int 3
00007FF67E575AAE mov rax,qword ptr [rcx-8]
00007FF67E575AB2 cmp rax,rcx
00007FF67E575AB5 jb show+50Eh (07FF67E575ABEh)
00007FF67E575AB7 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575ABD int 3
00007FF67E575ABE sub rcx,rax
00007FF67E575AC1 cmp rcx,8
00007FF67E575AC5 jae show+51Eh (07FF67E575ACEh)
00007FF67E575AC7 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
}
00007FF67E575ACD int 3
00007FF67E575ACE cmp rcx,27h
00007FF67E575AD2 jbe show+52Bh (07FF67E575ADBh)
00007FF67E575AD4 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575ADA int 3
00007FF67E575ADB mov rcx,rax
00007FF67E575ADE call operator delete (07FF67E57B430h)
00007FF67E575AE3 mov qword ptr [rbp-28h],7
00007FF67E575AEB mov qword ptr [rbp-30h],r12
00007FF67E575AEF mov word ptr [rbp-40h],r12w
00007FF67E575AF4 mov rax,qword ptr [rbp-48h]
00007FF67E575AF8 cmp rax,8
00007FF67E575AFC jb show+5AEh (07FF67E575B5Eh)
00007FF67E575AFE inc rax
00007FF67E575B01 mov rcx,qword ptr [rbp-60h]
00007FF67E575B05 cmp rax,r13
00007FF67E575B08 jbe show+561h (07FF67E575B11h)
00007FF67E575B0A call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575B10 int 3
00007FF67E575B11 add rax,rax
00007FF67E575B14 cmp rax,1000h
00007FF67E575B1A jb show+5A9h (07FF67E575B59h)
00007FF67E575B1C test byte ptr [rbp-60h],1Fh
00007FF67E575B20 je show+579h (07FF67E575B29h)
00007FF67E575B22 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575B28 int 3
00007FF67E575B29 mov rax,qword ptr [rcx-8]
00007FF67E575B2D cmp rax,rcx
00007FF67E575B30 jb show+589h (07FF67E575B39h)
00007FF67E575B32 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575B38 int 3
00007FF67E575B39 sub rcx,rax
00007FF67E575B3C cmp rcx,8
00007FF67E575B40 jae show+599h (07FF67E575B49h)
00007FF67E575B42 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575B48 int 3
00007FF67E575B49 cmp rcx,27h
00007FF67E575B4D jbe show+5A6h (07FF67E575B56h)
00007FF67E575B4F call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575B55 int 3
00007FF67E575B56 mov rcx,rax
00007FF67E575B59 call operator delete (07FF67E57B430h)
00007FF67E575B5E mov qword ptr [rbp-48h],7
00007FF67E575B66 mov qword ptr [rbp-50h],r12
00007FF67E575B6A mov word ptr [rbp-60h],r12w
00007FF67E575B6F mov rax,qword ptr [rbp-8]
00007FF67E575B73 cmp rax,8
00007FF67E575B77 jb show+629h (07FF67E575BD9h)
00007FF67E575B79 inc rax
00007FF67E575B7C mov rcx,qword ptr [rbp-20h]
00007FF67E575B80 cmp rax,r13
00007FF67E575B83 jbe show+5DCh (07FF67E575B8Ch)
00007FF67E575B85 call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575B8B int 3
00007FF67E575B8C add rax,rax
00007FF67E575B8F cmp rax,1000h
00007FF67E575B95 jb show+624h (07FF67E575BD4h)
00007FF67E575B97 test byte ptr [rbp-20h],1Fh
00007FF67E575B9B je show+5F4h (07FF67E575BA4h)
00007FF67E575B9D call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575BA3 int 3
00007FF67E575BA4 mov rax,qword ptr [rcx-8]
00007FF67E575BA8 cmp rax,rcx
00007FF67E575BAB jb show+604h (07FF67E575BB4h)
00007FF67E575BAD call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575BB3 int 3
00007FF67E575BB4 sub rcx,rax
00007FF67E575BB7 cmp rcx,8
00007FF67E575BBB jae show+614h (07FF67E575BC4h)
00007FF67E575BBD call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575BC3 int 3
00007FF67E575BC4 cmp rcx,27h
00007FF67E575BC8 jbe show+621h (07FF67E575BD1h)
00007FF67E575BCA call qword ptr [__imp__invalid_parameter_noinfo_noreturn (07FF67E57D318h)]
00007FF67E575BD0 int 3
00007FF67E575BD1 mov rcx,rax
00007FF67E575BD4 call operator delete (07FF67E57B430h)
最佳答案
控制台窗口的输出速度很慢,因为需要进行大量滚动(在文本缓冲区和屏幕上)。您可以将程序输出重定向到一个文件,性能应该与没有输出的版本相似。
不过,要进一步减少运行所需的时间,您需要尽可能减少字符串的使用。与其使用一系列 +
字符串操作(使用 3 个临时字符串对象),不如创建一个空字符串,在其中为整个构造的字符串保留足够的空间,然后使用 +=
添加单个组件。将其设为静态变量以避免额外的内存分配,并且仅在需要更多空间时才调整其大小。
关于c++ - 使用 std::wcout 会降低奇怪的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51344666/
我有这种来自 Google map 自动完成的奇怪行为(或者我可能错过了某事)...想法?奇怪的: 您在输入中输入某物,例如“伦敦” 您按 [ENTER] 你按下 [CLEAR] 按钮 你点击进入'输
这段代码与《Learning Java》(Oracle Press Books)一书中的代码完全一样,但它不起作用。我不明白为什么它不起作用,它应该起作用。我用 OpenJDK 和 Sun JDK 7
示例 1 中究竟发生了什么?这是如何解析的? # doesnt split on , [String]::Join(",",("aaaaa,aaaaa,aaaaa,aaaaa,aaaaa,aa
我需要获得方程式系统的解决方案。为此,我使用函数sgesv_()。 一切都很好,它使我感到解决方案的正确结果。 但是我得到一个奇怪的警告。 警告:从不兼容的指针类型传递'sgesv_'的参数3 我正在
我目前在制作动画时遇到一个奇怪的问题: [UIView animateWithDuration:3 delay:0
alert('works'); $(window).load(function () { alert('does not work'); });
我的代码: public class MyTest { public class StringSorter implements Comparator { public
我正在学习 JavaScript。尝试理解代码, function foo (){ var a = b = {name: 'Hai'}; document.write(a.name +''
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
这按预期工作: [dgorur@ted ~]$ env -i env [dgorur@ted ~]$ 这样做: [dgorur@ted ~]$ env -i which date which: no
struct BLA { int size_; int size()const{ return size_; } } int x; BLA b[ 2 ]; BLA * p = &b[
我有以下代码: #test img {vertical-align: middle;} div#test { border: 1px solid green; height: 150px; li
我想大多数使用过 C/C++ 的人都对预处理器的工作原理有一定的直觉(或多或少)。直到今天我也是这么认为的,但事实证明我的直觉是错误的。故事是这样的: 今天我尝试了一些东西,但我无法解释结果。首先考虑
我想为 TnSettings 做 mock,是的,如果通过以下方法编写代码,它就可以工作,问题是我们需要为每个案例编写 mock 代码,如果我们只 mock 一次然后执行多个案例,那么第二个将报告异常
我的项目中有以下两个结构 typedef volatile struct { unsigned char rx_buf[MAX_UART_BUF]; //Input buffer over U
Regex rx = new Regex(@"[+-]"); string[] substrings = rx.Split(expression); expression = "-9a3dcb
我的两个应用程序遇到了一个奇怪的问题。这是设置: 两个 tomcat/java 应用程序,在同一个网络中运行,连接到相同的 MS-SQL-Server。一个应用程序,恰好按顺序位于 DMZ 中可从互联
我目前正在与 Android Api Lvl 8 上的 OnLongClickListener 作斗争。 拿这段代码: this.webView.setOnLongClickListener(new
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
只是遇到了奇怪的事情。我有以下代码: -(void)ImageDownloadCompleat { [self performSelectorOnMainThread:@selector(up
我是一名优秀的程序员,十分优秀!