_PROCESS_MEMORY_COUNTERS给出了关于内存使用的负值 [英] _PROCESS_MEMORY_COUNTERS is giving negative values about memory usage
本文介绍了_PROCESS_MEMORY_COUNTERS给出了关于内存使用的负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过我的应用程序获得内存使用。我按照此
I am trying to get memory usage by my application. I followed this
这里是我写的代码,但是在1 GB之后它给出了负值。
Here is code that I write but after 1 GB it is giving negative values.
_PROCESS_MEMORY_COUNTERS info;
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) );
int membyte = ((size_t)info.WorkingSetSize);
QString s1 = "MB";
double mem = membyte/1048576.0;
if(mem>900.0)
{
mem = mem/1024.0;
s1 = "GB";
}
double f,i,t1,t2;
f = modf (mem , &i);
f = f*100;
t1 = modf(f,&t2);
mem = i + (t2/100.0);
推荐答案
int membyte = ((size_t)info.WorkingSetSize);
不要这样做。不能保证工作集大小将在 int
表示的范围内。也许你想使用 unsigned long
或更好地使用 SIZE_T
。
Don't do that. There's no guarantee the working set size will be in the range an int
can represent. Perhaps you want to use an unsigned long
or, better yet, a SIZE_T
.
这篇关于_PROCESS_MEMORY_COUNTERS给出了关于内存使用的负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文