c++ - Getting "Physical Memory currently used by current process" error in Qt -


i'm trying in qt 5.5 "physical memory used current process" tutorial: how system cpu/ram usage in c++ on windows when i'm trying add function application i'm getting error...

process_memory_counters_ex pmc; getprocessmemoryinfo(getcurrentprocess(), &pmc, sizeof(pmc)); // error c2664 size_t physmemusedbyme = pmc.workingsetsize; 

error:

c2664: 'bool k32getprocessmemoryinfo(handle,pprocess_memory_counters,dword)' : cannot convert argument 2 'process_memory_counters_ex *' 'pprocess_memory_counters' types pointed unrelated; conversion requires reinterpret_cast, c-style cast or function-style cast 

thank help.

according documentation getprocessmemoryinfo can accept either pointer process_memory_counters or process_memory_counters_ex. latest type contains 1 additional field.

it might depend on sdk version, in header psapi.h function declared pointer process_memory_counters. so, extended structure version fails compile.

both solutions work:

// use process_memory_counters structure process_memory_counters pmc;  // or cast structure type process_memory_counters_ex pmc; getprocessmemoryinfo(getcurrentprocess(),     reinterpret_cast<pprocess_memory_counters>(&pmc), sizeof(pmc)); 

sinse getprocessmemoryinfo has structure size argument, extended structure process_memory_counters_ex filled.


Comments