在Qt中出现"Physical Memory currently used by current process"错误
Getting "Physical Memory currently used by current process" error in Qt
我正在尝试在Qt 5.5中获得"当前进程当前使用的物理内存"与本教程:如何获得系统cpu/ram使用在Windows上的c++当我试图将此函数添加到我的应用程序时,我得到一个错误…
PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); // error C2664
SIZE_T physMemUsedByMe = pmc.WorkingSetSize;
错误:C2664: 'BOOL K32GetProcessMemoryInfo(HANDLE,PPROCESS_MEMORY_COUNTERS,DWORD)' : cannot convert argument 2 from 'PROCESS_MEMORY_COUNTERS_EX *' to 'PPROCESS_MEMORY_COUNTERS'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
谢谢你的帮助。
根据文档GetProcessMemoryInfo可以接受指向PROCESS_MEMORY_COUNTERS
或PROCESS_MEMORY_COUNTERS_EX
的指针。最新的类型包含一个额外的字段。
它可能取决于SDK版本,但是在我的头psapi.h
中,该函数仅用指向PROCESS_MEMORY_COUNTERS
的指针声明。因此,扩展结构版本无法编译。
两种方法都有效:
// use only PROCESS_MEMORY_COUNTERS structure
PROCESS_MEMORY_COUNTERS pmc;
// or cast structure type
PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(),
reinterpret_cast<PPROCESS_MEMORY_COUNTERS>(&pmc), sizeof(pmc));
由于GetProcessMemoryInfo
也有结构体大小作为参数,扩展的结构体PROCESS_MEMORY_COUNTERS_EX
也被填充。
我没有足够的声誉来评论。我从你的问题中得到的信息有限。如果我处在你的位置,我会试着指导你怎么做。
- 你是使用Qt与mingw32或visual studio?
你提到的过程将不工作与Qt使用mingw32。这是为visual studio准备的。
- 如果你正在使用Visual studio尝试遵循没有Qt介入的方法,即为它编写一个独立的程序。如果它仍然给出错误检查MSDN 的函数原型
相关文章:
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- 将 std::thread by 值推送到列表中
- MATLAB to C++: csvread() not supported by MATLAB Coder
- 调试控制台 ChessEngine.exe "used"在另一个应用程序(国际象棋 GUI)中
- C++ - 在我尝试制作一个简单的计算器时有一个"uninitialized local variable y used"警告
- Makefile by ocaml 和 cpp 扩展名
- SFINAE:"enable_if cannot be used to disable this declaration"
- 行 - " vector<int> used(adj.size(), 0); "是什么意思?
- 如何理解"abstract-declarator containing an ellipsis shall only be used in a parameter-declaration"
- C++ OpenCV Randu 函数抛出'Integer division by zero'
- 从函数 BY VALUE 返回数组,返回结构时会发生什么?
- 如何在不受其他文件影响的情况下"by itself" Visual Studio 项目中运行C++文件?
- 解决方法:'can not be used when making a shared object; recompile with -fPIC'使用Cmake。使用普通的 g++ 工作
- С 错误"s1, s2 are used uninitialised in this function"
- "expression cannot be used as a function"回报声明
- MacPorts:"Error: clang-4.0 has been replaced by clang-8.0; please install that instead",但我已经安装了clang
- 为什么 c++ 向量没有"delete by index"?
- 这个给定的代码应该将给定的数字转换为尽可能滞后的数字,no.by 用 9.It 替换合适的数字是行不通的
- 传递类 by-value 时,调用方或被调用方是否调用析构函数
- 在Qt中出现"Physical Memory currently used by current process"错误