Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Foundation/Memory/Common.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#if qStroika_Foundation_Common_Platform_Windows
7#include <windows.h>
8
9#include <Psapi.h>
10#endif
11
13
14#include "Common.h"
15
16using namespace Stroika::Foundation;
17
18/*
19 ********************************************************************************
20 ******************* Memory::GetGlobalAllocationStatistics **********************
21 ********************************************************************************
22 */
23Memory::GlobalAllocationStatistics Memory::GetGlobalAllocationStatistics ()
24{
25 GlobalAllocationStatistics s;
26#if qStroika_Foundation_Common_Platform_Windows
27 HANDLE hProcess = ::OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ::GetCurrentProcessId ());
28 if (hProcess != nullptr) {
29#pragma comment(lib, "Psapi.lib")
30 PROCESS_MEMORY_COUNTERS pmc{};
31 pmc.cb = sizeof (pmc);
32 if (::GetProcessMemoryInfo (hProcess, &pmc, sizeof (pmc))) {
33 s.fPageFaultCount = pmc.PageFaultCount;
34 s.fPagefileUsage = pmc.PagefileUsage;
35 s.fWorkingSetSize = pmc.WorkingSetSize;
36#if qOverrideOpNewDeleteForAccounting
37 s.fTotalOutstandingAllocations = GetAllocator_ ().GetNetAllocationCount ();
38 s.fTotalOutstandingBytesAllocated = GetAllocator_ ().GetNetAllocatedByteCount ();
39#elif qStroika_Foundation_Debug_AssertionsChecked
40 _CrtMemState memState;
41 _CrtMemCheckpoint (&memState);
42 s.fTotalOutstandingAllocations = memState.lCounts[_NORMAL_BLOCK] + memState.lCounts[_CLIENT_BLOCK];
43 s.fTotalOutstandingBytesAllocated = memState.lSizes[_NORMAL_BLOCK] + memState.lSizes[_CLIENT_BLOCK];
44#endif
45 }
46 ::CloseHandle (hProcess);
47 }
48#endif
49 return s;
50}