Microsoft Visual C ++ 2010 Express中的物理和虚拟内存消耗计算

时间:2016-07-28 21:53:41

标签: c++ c visual-studio visual-studio-2010 visual-c++

Code response at Code Blocks(MinGW)如何获取有关物理内存,虚拟内存和信息的信息? CPU注册使用我的" .c"在Microsoft Visual C ++ 2010 Express中运行的代码?Code response with VC++ 2010 Express

首先让我深入澄清我的问题。 我是Visual Studio的新手。每次我使用" Code Blocks"使用GNU GCC编译器(mingW)。 如果我只专注于Physical&虚拟内存使用。这是我用于mingW的测试目的的小代码。它运作正常。

#include <windows.h>
#include<stdio.h>
#include<stdlib.h>
#define DIV 1024
#define WI 7
#include <Psapi.h>


 void main()
{
 int a;float b;char c;
 const unsigned char tmpe[320];
 static const float weights[422];
 printf("sz of a is %d \n",sizeof(a));
 printf("sz of b is %d \n",sizeof(b));
 printf("size of frames is %d \n", sizeof(tmpe));
 printf("sz of c is %d \n",sizeof(c));
 printf("size of yooo is %d \n", sizeof(weights));

PROCESS_MEMORY_COUNTERS_EX vm_cp;

GetProcessMemoryInfo(GetCurrentProcess(),  
(PROCESS_MEMORY_COUNTERS*)&vm_cp,sizeof(vm_cp));  

SIZE_T virtualMemoryusedbyMyCp = vm_cp.PrivateUsage; /* Virtual memory   
currently used by current process, vm_cp = virtual memory of current process */

printf ("There are %*I64d Kbytes of virtual memory used by my Current 
Process.\n",
       WI, virtualMemoryusedbyMyCp/DIV);

SIZE_T physMemoryUsedbyMyCP = vm_cp.WorkingSetSize; /*Physical Memory used by  
Current Process */

printf ("There are %*I64d Kbytes of Physical memory used by my Current   
Process.\n",WI, physMemoryUsedbyMyCP/DIV);


 }

但是当我在Visual Studio 2010 Express中使用相同的代码时

我收到了这个我无法理解的错误列表。 以下是VS 2010 express的编译错误

1>------ Build started: Project: Yooo_size code, Configuration: Debug Win32   
------

1>  size demo.c
1>size demo.c(50): error C2275: 'PROCESS_MEMORY_COUNTERS_EX' : illegal use of 
this type as an expression

1> C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\Psapi.h(394) : see 
declaration of 'PROCESS_MEMORY_COUNTERS_EX'

1>size demo.c(50): error C2146: syntax error : missing ';' before identifier 
'vm_cp'

1>size demo.c(50): error C2065: 'vm_cp' : undeclared identifier
1>size demo.c(51): error C2065: 'vm_cp' : undeclared identifier
1>size demo.c(51): error C2065: 'vm_cp' : undeclared identifier
1>size demo.c(52): error C2275: 'SIZE_T' : illegal use of this type as an   
expression

1> C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\basetsd.h(421) : see 
declaration of 'SIZE_T'

1>size demo.c(52): error C2146: syntax error : missing ';' before identifier 
'virtualMemoryusedbyMyCp'

1>size demo.c(52): error C2065: 'virtualMemoryusedbyMyCp' : undeclared 
identifier

1>size demo.c(52): error C2065: 'vm_cp' : undeclared identifier
1>size demo.c(52): error C2224: left of '.PrivateUsage' must have struct/union 
type

1>size demo.c(54): error C2065: 'virtualMemoryusedbyMyCp' : undeclared 
identifier

1>size demo.c(55): error C2275: 'SIZE_T' : illegal use of this type as an 
expression
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\basetsd.h(421) : see 
declaration of 'SIZE_T'
1>size demo.c(55): error C2146: syntax error : missing ';' before identifier 
'physMemoryUsedbyMyCP'

1>size demo.c(55): error C2065: 'physMemoryUsedbyMyCP' : undeclared identifier
1>size demo.c(55): error C2065: 'vm_cp' : undeclared identifier
1>size demo.c(55): error C2224: left of '.WorkingSetSize' must have 
struct/union type

1>size demo.c(57): error C2065: 'physMemoryUsedbyMyCP' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

0 个答案:

没有答案