fork download
  1. #define PSAPI_VERSION 1
  2. #include <iostream>
  3. #include "time.h"
  4. #include "Windows.h"
  5. #include "winbase.h"
  6. #include "psapi.h"
  7.  
  8. const int cellNum = 1000;
  9. const int cellSize = 1024 * 1024;
  10.  
  11. size_t GetPeakWorkingSetInMbMYYY(size_t processID = 0)
  12. {
  13. if (processID == 0)
  14. processID = GetCurrentProcessId();
  15. HANDLE hProcess;
  16. PROCESS_MEMORY_COUNTERS pmc;
  17. size_t toRet = 0;
  18. hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
  19. PROCESS_VM_READ,
  20. FALSE, static_cast<DWORD>(processID));
  21. if (NULL == hProcess)
  22. {
  23. std::cout << "smth wrong" << std::endl;
  24. exit(0);
  25. }
  26.  
  27. if ( GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))
  28. {
  29. toRet = pmc.PeakWorkingSetSize;
  30. }
  31. CloseHandle(hProcess);
  32. return toRet/1000000;
  33. }
  34.  
  35. int main()
  36. {
  37. Sleep(1000);
  38. char** val = (char**)malloc(cellNum * sizeof(char*));
  39. for (int i = 0; i < cellNum; i++)
  40. {
  41. val[i] =(char*)malloc(cellSize * sizeof(char));
  42. //std::cout << i + 1 << " cells allocated" << std::endl;
  43. }
  44. std::cout << "total allocated cells: " << cellNum << std::endl;
  45. std::cout << "total allocated bytes: " << GetPeakWorkingSetInMbMYYY() << std::endl;
  46. val;
  47. Sleep(10000);
  48. return 0;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:21: fatal error: Windows.h: No such file or directory
 #include "Windows.h"
                     ^
compilation terminated.
stdout
Standard output is empty