11#include " stdafx.h"
2- #pragma hdrstop
32
4- #include " xrsharedmem.h "
5- #include " xrCore/_std_extensions .h"
3+ #include < Psapi.h >
4+ #include " tbb/scalable_allocator .h"
65
76xrMemory Memory;
87// Also used in src\xrCore\xrDebug.cpp to prevent use of g_pStringContainer before it initialized
98bool shared_str_initialized = false ;
109
11- // fake fix of memory corruptions in multiplayer game :(
12- // XXX nitrocaster: to be removed
13- XRCORE_API bool g_allow_heap_min = true ;
14-
1510xrMemory::xrMemory ()
1611{
1712}
@@ -57,32 +52,20 @@ XRCORE_API void log_vminfo()
5752
5853size_t xrMemory::mem_usage ()
5954{
60- _HEAPINFO hinfo = {};
61- int status;
62- size_t bytesUsed = 0 ;
63- while ((status = _heapwalk (&hinfo)) == _HEAPOK)
64- {
65- if (hinfo._useflag == _USEDENTRY)
66- bytesUsed += hinfo._size ;
67- }
68- switch (status)
55+ PROCESS_MEMORY_COUNTERS pmc = {};
56+ if (HANDLE h = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE , GetCurrentProcessId ()))
6957 {
70- case _HEAPEMPTY: break ;
71- case _HEAPEND: break ;
72- case _HEAPBADPTR: FATAL (" bad pointer to heap" ); break ;
73- case _HEAPBADBEGIN: FATAL (" bad start of heap" ); break ;
74- case _HEAPBADNODE: FATAL (" bad node in heap" ); break ;
58+ GetProcessMemoryInfo (h, &pmc, sizeof (pmc));
59+ CloseHandle (h);
7560 }
76- return bytesUsed ;
61+ return pmc. PagefileUsage ;
7762}
7863
7964void xrMemory::mem_compact ()
8065{
8166 RegFlushKey (HKEY_CLASSES_ROOT);
8267 RegFlushKey (HKEY_CURRENT_USER);
83- if (g_allow_heap_min)
84- _heapmin ();
85- HeapCompact (GetProcessHeap (), 0 );
68+ scalable_allocation_command (TBBMALLOC_CLEAN_ALL_BUFFERS, NULL );
8669 if (g_pStringContainer)
8770 g_pStringContainer->clean ();
8871 if (g_pSharedMemoryContainer)
@@ -94,27 +77,27 @@ void xrMemory::mem_compact()
9477void * xrMemory::mem_alloc (size_t size)
9578{
9679 stat_calls++;
97- return malloc (size);
80+ return scalable_malloc (size);
9881}
9982
10083void xrMemory::mem_free (void * P)
10184{
10285 stat_calls++;
103- free (P);
86+ scalable_free (P);
10487}
10588
10689void * xrMemory::mem_realloc (void * P, const size_t size)
10790{
10891 stat_calls++;
109- return realloc (P, size);
92+ return scalable_realloc (P, size);
11093}
11194
11295// xr_strdup
11396pstr xr_strdup (pcstr string)
11497{
11598 VERIFY (string);
11699 size_t len = xr_strlen (string) + 1 ;
117- char * memory = (char *)Memory. mem_alloc (len);
100+ char * memory = (char *)xr_malloc (len);
118101 CopyMemory (memory, string, len);
119102 return memory;
120103}
0 commit comments