Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find total memory requirements?

Status
Not open for further replies.

Skywise

Programmer
Apr 11, 2001
9
US
How can I find out how much memory my program needs (or is using) at a given time (without using sizeof on every single varible?). I would like to display the total memory used at a given time by the program. How can I do that?
 
You can do it only by counting at runtime the memory what you use. Don't forget what the code also use memory. John Fill
1c.bmp


ivfmd@mail.md
 
Check out the API function GetProcessMemoryInfo

BOOL GetProcessMemoryInfo(
HANDLE Process, // handle to process
PPROCESS_MEMORY_COUNTERS ppsmemCounters, // buffer
DWORD cb // size of buffer
);

to get a handle tot the current process you need to use
GetCurrentProcess() API Call

You will need Psapi.h and Psapi.lib files.
Anyway this work only on NT 4.0 or higher.

Good luck, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
It seems that the files psapi.h and psapi.lib you cannot find in the standard include directory.(strange is MS sometimes!).

Anyway you can find the in the Pfmon sample from the MSDN Samples.

After I found the files I had run a sample like this and it worked perfect:

HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc;
hProcess=GetCurrentProcess();
GetProcessMemoryInfo(hProcess,&pmc,sizeof(pmc));

// now in the pmc structure you have all the information you need

Hope this helps,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top