Fortune Telling Collection - Comprehensive fortune-telling - How to calculate how much memory a program takes up when it runs?

How to calculate how much memory a program takes up when it runs?

You can use system (command) to call DOS/Windows command to get the amount of memory in use.

Command example:

Wmic process, where name="cmd.exe "gets WorkingSetSize.

You can replace "cmd.exe" here with your program name.

You can also use your program process PID number to call, the command is:

Wmic process with processid=6884 gets WorkingSetSize.

Here, you can replace 6884 with your program process PID.

The output has 2 lines, and the second line is the number of bytes occupied by memory:

WorkingSetSize

46 16 192

C/c++ language:

system(" wmic process where processid = 6884 get WorkingSetSize ");

System("wmic process, where name = \ "cmd.exe \" get working setsize ");

When calling with a program name, if there are multiple programs with the same name running, the output memory will be output line by line.