swh:1:snp:c78d7a14cc07423acb6a43d0e3059b9afd67996a
Tip revision: c5be799ee3dad53f5edf10eeb39527bbca5add11 authored by LorenzoDiazzi on 29 May 2025, 10:15:58 UTC
Update README.md
Update README.md
Tip revision: c5be799
winMem.cpp
#include <stdio.h>
#ifdef _MSC_VER
#include <windows.h>
#include <psapi.h>
// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
// and compile with -DPSAPI_VERSION=1
double getPeakMegabytesUsed()
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId());
if (NULL == hProcess) return 0;
PROCESS_MEMORY_COUNTERS pmc;
double mem = 0;
if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
{
mem = pmc.PeakWorkingSetSize / 1048576.0;
}
CloseHandle(hProcess);
return mem;
}
void PrintMemoryInfo()
{
printf("Peak memory usage (Mb): %f\n", getPeakMegabytesUsed());
}
#else
void PrintMemoryInfo() {
printf("Peak memory usage unavailable. This feature is implemented on Windows/MSVC only.\n");
}
#endif