Skip to content

Commit

Permalink
Work of Memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr committed Feb 27, 2018
1 parent 5a5f18d commit 8ef9f47
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 36 deletions.
3 changes: 3 additions & 0 deletions src/editors/xrWeatherEditor/xrWeatherEditor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@
<ProjectReference Include="$(SolutionDir)editors\xrSdkControls\xrSdkControls.csproj">
<Project>{e9dc16a3-d0fa-4924-af6e-f6fdf3ea0661}</Project>
</ProjectReference>
<ProjectReference Include="..\..\xrCore\xrCore.vcxproj">
<Project>{a0f7d1fb-59a7-4717-a7e4-96f37e91998e}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
41 changes: 12 additions & 29 deletions src/xrCore/xrMemory.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#include "stdafx.h"
#pragma hdrstop

#include "xrsharedmem.h"
#include "xrCore/_std_extensions.h"
#include <Psapi.h>
#include "tbb/scalable_allocator.h"

xrMemory Memory;
// Also used in src\xrCore\xrDebug.cpp to prevent use of g_pStringContainer before it initialized
bool shared_str_initialized = false;

// fake fix of memory corruptions in multiplayer game :(
// XXX nitrocaster: to be removed
XRCORE_API bool g_allow_heap_min = true;

xrMemory::xrMemory()
{
}
Expand Down Expand Up @@ -57,32 +52,20 @@ XRCORE_API void log_vminfo()

size_t xrMemory::mem_usage()
{
_HEAPINFO hinfo = {};
int status;
size_t bytesUsed = 0;
while ((status = _heapwalk(&hinfo)) == _HEAPOK)
{
if (hinfo._useflag == _USEDENTRY)
bytesUsed += hinfo._size;
}
switch (status)
PROCESS_MEMORY_COUNTERS pmc = {};
if (HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId()))
{
case _HEAPEMPTY: break;
case _HEAPEND: break;
case _HEAPBADPTR: FATAL("bad pointer to heap"); break;
case _HEAPBADBEGIN: FATAL("bad start of heap"); break;
case _HEAPBADNODE: FATAL("bad node in heap"); break;
GetProcessMemoryInfo(h, &pmc, sizeof(pmc));
CloseHandle(h);
}
return bytesUsed;
return pmc.PagefileUsage;
}

void xrMemory::mem_compact()
{
RegFlushKey(HKEY_CLASSES_ROOT);
RegFlushKey(HKEY_CURRENT_USER);
if (g_allow_heap_min)
_heapmin();
HeapCompact(GetProcessHeap(), 0);
scalable_allocation_command(TBBMALLOC_CLEAN_ALL_BUFFERS, NULL);
if (g_pStringContainer)
g_pStringContainer->clean();
if (g_pSharedMemoryContainer)
Expand All @@ -94,27 +77,27 @@ void xrMemory::mem_compact()
void* xrMemory::mem_alloc(size_t size)
{
stat_calls++;
return malloc(size);
return scalable_malloc(size);
}

void xrMemory::mem_free(void* P)
{
stat_calls++;
free(P);
scalable_free(P);
}

void* xrMemory::mem_realloc(void* P, const size_t size)
{
stat_calls++;
return realloc(P, size);
return scalable_realloc(P, size);
}

// xr_strdup
pstr xr_strdup(pcstr string)
{
VERIFY(string);
size_t len = xr_strlen(string) + 1;
char* memory = (char*)Memory.mem_alloc(len);
char* memory = (char*)xr_malloc(len);
CopyMemory(memory, string, len);
return memory;
}
1 change: 0 additions & 1 deletion src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ ENGINE_API void Startup()

// Main cycle
splash::hide();
Memory.mem_usage();
Device.Run();
// Destroy APP
xr_delete(g_SpatialSpacePhysic);
Expand Down
7 changes: 1 addition & 6 deletions src/xrGame/Level_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "xrNetServer/NET_Messages.h"

int g_cl_save_demo = 0;
extern XRCORE_API bool g_allow_heap_min;

shared_str CLevel::OpenDemoFile(const char* demo_file_name)
{
Expand Down Expand Up @@ -116,7 +115,6 @@ bool CLevel::net_start1()
}
else
{
g_allow_heap_min = false;
Server = new xrGameSpyServer();
}

Expand All @@ -139,10 +137,7 @@ bool CLevel::net_start1()
}
}
}
else
{
g_allow_heap_min = false;
}

return true;
}

Expand Down

0 comments on commit 8ef9f47

Please sign in to comment.