Skip to content

Commit 8ef9f47

Browse files
committed
Work of Memory.
1 parent 5a5f18d commit 8ef9f47

File tree

4 files changed

+16
-36
lines changed

4 files changed

+16
-36
lines changed

src/editors/xrWeatherEditor/xrWeatherEditor.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@
357357
<ProjectReference Include="$(SolutionDir)editors\xrSdkControls\xrSdkControls.csproj">
358358
<Project>{e9dc16a3-d0fa-4924-af6e-f6fdf3ea0661}</Project>
359359
</ProjectReference>
360+
<ProjectReference Include="..\..\xrCore\xrCore.vcxproj">
361+
<Project>{a0f7d1fb-59a7-4717-a7e4-96f37e91998e}</Project>
362+
</ProjectReference>
360363
</ItemGroup>
361364
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
362365
<ImportGroup Label="ExtensionTargets">

src/xrCore/xrMemory.cpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
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

76
xrMemory Memory;
87
// Also used in src\xrCore\xrDebug.cpp to prevent use of g_pStringContainer before it initialized
98
bool 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-
1510
xrMemory::xrMemory()
1611
{
1712
}
@@ -57,32 +52,20 @@ XRCORE_API void log_vminfo()
5752

5853
size_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

7964
void 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()
9477
void* xrMemory::mem_alloc(size_t size)
9578
{
9679
stat_calls++;
97-
return malloc(size);
80+
return scalable_malloc(size);
9881
}
9982

10083
void xrMemory::mem_free(void* P)
10184
{
10285
stat_calls++;
103-
free(P);
86+
scalable_free(P);
10487
}
10588

10689
void* 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
11396
pstr 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
}

src/xrEngine/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ ENGINE_API void Startup()
184184

185185
// Main cycle
186186
splash::hide();
187-
Memory.mem_usage();
188187
Device.Run();
189188
// Destroy APP
190189
xr_delete(g_SpatialSpacePhysic);

src/xrGame/Level_start.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "xrNetServer/NET_Messages.h"
1717

1818
int g_cl_save_demo = 0;
19-
extern XRCORE_API bool g_allow_heap_min;
2019

2120
shared_str CLevel::OpenDemoFile(const char* demo_file_name)
2221
{
@@ -116,7 +115,6 @@ bool CLevel::net_start1()
116115
}
117116
else
118117
{
119-
g_allow_heap_min = false;
120118
Server = new xrGameSpyServer();
121119
}
122120

@@ -139,10 +137,7 @@ bool CLevel::net_start1()
139137
}
140138
}
141139
}
142-
else
143-
{
144-
g_allow_heap_min = false;
145-
}
140+
146141
return true;
147142
}
148143

0 commit comments

Comments
 (0)