File: utils_win32.cpp

package info (click to toggle)
pilercr 1.06%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 844 kB
  • sloc: cpp: 14,339; makefile: 67; sh: 36
file content (37 lines) | stat: -rwxr-xr-x 698 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "pilercr.h"

#if	WIN32
#include <windows.h>
#include <psapi.h>

double GetRAMSize()
	{
	MEMORYSTATUS MS;
	GlobalMemoryStatus(&MS);
	double m = (double) MS.dwTotalPhys;
	if (m > 1.8e9)
		m = 1.8e9;
	return (unsigned) m;
	}

static unsigned g_uPeakMemUseBytes;

unsigned GetPeakMemUseBytes()
	{
	return g_uPeakMemUseBytes;
	}

unsigned GetMemUseBytes()
	{
	HANDLE hProc = GetCurrentProcess();
	PROCESS_MEMORY_COUNTERS PMC;
	BOOL bOk = GetProcessMemoryInfo(hProc, &PMC, sizeof(PMC));
	if (!bOk)
		return 1000000;
	unsigned uBytes = (unsigned) PMC.WorkingSetSize;
	if (uBytes > g_uPeakMemUseBytes)
		g_uPeakMemUseBytes = uBytes;
	return uBytes;
	}

#endif