0

Code response at Code Blocks(MinGW)How can I get the information about the Physical Memory, Virtual Memory & CPU register usage of my ".c" code running in Microsoft Visual C++ 2010 Express ?Code response with VC++ 2010 Express

First let me clarify my issues in depth. I'm new to Visual Studio. Every time I used "Code Blocks" with GNU GCC compiler (mingW). For the timing if I just focus on Physical & Virtual memory usage. Here is the small code just for testing purpose which I used with mingW. It worked properly.

#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);


 }

But when I used the same code with Visual studio 2010 express

I'm getting this long list of errors which I'm unable to understand. Here is the compilation error with 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 ==========
Yoo Yooo
  • 1
  • 1
  • 1
    What sort of metric is *"CPU register usage"* for? It's not like you can do anything to change it. – IInspectable Jul 28 '16 at 22:01
  • @IInspectable I know, can't do anything to change it and I know this parameter depends at the time of usage. Actually I'm working on Audio codec development so if I get the bare basic idea about the memory usage by my code then it would be better. – Yoo Yooo Jul 29 '16 at 07:12
  • *"Windef.h"* is not a header file you should include. You need to include *"Windows.h"* instead, and ideally make it the very first include (unless you are using *Winsock2.h*). – IInspectable Jul 29 '16 at 09:22
  • @IInspectable I changed the sequence and also removed unnecessary headers. But still I'm getting lot of errors & if you look at the errors this "Psapi.h" is unable to recognize the objects of that structure type defined in psapi. basetsd.h is another issue. – Yoo Yooo Jul 29 '16 at 10:44
  • Since the first error is reported for line 50, I'm assuming that the code you posted and the code you compiled are different. This isn't going to be helpful. Please provide a [mcve], and post it **unabridged**. – IInspectable Jul 29 '16 at 10:51
  • @IInspectable the given code is same I didn't change anything when I was posting over here. I've attached the screenshot of results of my dummy given code with "Code Blocks" and "VC++ 2010" Express for cross verification. – Yoo Yooo Jul 29 '16 at 11:29
  • [PROCESS_MEMORY_COUNTERS_EX](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684874.aspx) is declared only when targeting Windows XP and later. Did you `#define _WIN32_WINNT 0x0501` (or higher) before including *Windows.h*? – IInspectable Jul 29 '16 at 11:51
  • @IInspectable Yes I declared that, even though i also tried with #define _WIN32_WINNT 0x0601 (when I was on Win 7) before including Windows.h Still I'm getting the same kind of error. – Yoo Yooo Jul 29 '16 at 12:21
  • None of that is visible in the code you posted, so we cannot help you. Please provide a [mcve], including the command line arguments passed to your compiler. – IInspectable Jul 29 '16 at 12:25

0 Answers0