mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 08:15:44 +00:00
Update platformMemory.cpp
undo experimental changes to platformMemory.cpp
This commit is contained in:
parent
700bf32a2a
commit
4a1019619f
1 changed files with 5 additions and 20 deletions
|
|
@ -30,9 +30,6 @@
|
||||||
#include "platform/threads/mutex.h"
|
#include "platform/threads/mutex.h"
|
||||||
#include "core/module.h"
|
#include "core/module.h"
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <dbghelp.h>
|
#include <dbghelp.h>
|
||||||
|
|
@ -60,7 +57,7 @@
|
||||||
#ifdef TORQUE_MULTITHREAD
|
#ifdef TORQUE_MULTITHREAD
|
||||||
void* gMemMutex = NULL;
|
void* gMemMutex = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//-------------------------------------- Make sure we don't have the define set
|
//-------------------------------------- Make sure we don't have the define set
|
||||||
#ifdef new
|
#ifdef new
|
||||||
#undef new
|
#undef new
|
||||||
|
|
@ -75,11 +72,9 @@ namespace Memory
|
||||||
|
|
||||||
static const U32 MaxAllocs = 10240;
|
static const U32 MaxAllocs = 10240;
|
||||||
static MemInfo allocList[MaxAllocs];
|
static MemInfo allocList[MaxAllocs];
|
||||||
static std::atomic<U32> allocCount{ 0 };
|
static U32 allocCount = 0;
|
||||||
static std::atomic<U32> currentAllocId{ 0 };
|
static U32 currentAllocId = 0;
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
|
|
||||||
static std::mutex memMutex; // Use shared_mutex if you need more granularity
|
|
||||||
char gLogFilename[256] = { 0 };
|
char gLogFilename[256] = { 0 };
|
||||||
bool gStackTrace = true;
|
bool gStackTrace = true;
|
||||||
bool gFromScript = false;
|
bool gFromScript = false;
|
||||||
|
|
@ -101,7 +96,6 @@ namespace Memory
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(memMutex);
|
|
||||||
if (initialized) return;
|
if (initialized) return;
|
||||||
std::memset(allocList, 0, sizeof(allocList));
|
std::memset(allocList, 0, sizeof(allocList));
|
||||||
std::memset(memLog, 0, sizeof(memLog));
|
std::memset(memLog, 0, sizeof(memLog));
|
||||||
|
|
@ -119,11 +113,8 @@ namespace Memory
|
||||||
|
|
||||||
void shutdown()
|
void shutdown()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(memMutex);
|
|
||||||
if (!initialized) return;
|
if (!initialized) return;
|
||||||
|
|
||||||
initialized = false; // stop memlog from running now.
|
|
||||||
|
|
||||||
FILE* log = std::fopen(gLogFilename, "w");
|
FILE* log = std::fopen(gLogFilename, "w");
|
||||||
if (!log)
|
if (!log)
|
||||||
return;
|
return;
|
||||||
|
|
@ -227,7 +218,6 @@ namespace Memory
|
||||||
|
|
||||||
void checkPtr(void* ptr)
|
void checkPtr(void* ptr)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(memMutex);
|
|
||||||
for (U32 i = 0; i < allocCount; ++i)
|
for (U32 i = 0; i < allocCount; ++i)
|
||||||
if (allocList[i].ptr == ptr)
|
if (allocList[i].ptr == ptr)
|
||||||
return;
|
return;
|
||||||
|
|
@ -247,7 +237,6 @@ namespace Memory
|
||||||
if (!initialized || allocCount >= MaxAllocs)
|
if (!initialized || allocCount >= MaxAllocs)
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(memMutex);
|
|
||||||
MemInfo& info = allocList[allocCount++];
|
MemInfo& info = allocList[allocCount++];
|
||||||
info.ptr = ptr;
|
info.ptr = ptr;
|
||||||
info.size = size;
|
info.size = size;
|
||||||
|
|
@ -261,7 +250,7 @@ namespace Memory
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
info.backtraceSize = CaptureStackBackTrace(0, 16, info.backtracePtrs, nullptr);
|
info.backtraceSize = CaptureStackBackTrace(0, 16, info.backtracePtrs, nullptr);
|
||||||
#else
|
#else
|
||||||
info.backtraceSize = backtrace(info.backtracePtrs, 16);
|
info.backtraceSize = backtrace(info.backtracePtrs, MaxBacktraceDepth);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,8 +268,6 @@ namespace Memory
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(memMutex);
|
|
||||||
|
|
||||||
for (U32 i = 0; i < allocCount; ++i)
|
for (U32 i = 0; i < allocCount; ++i)
|
||||||
{
|
{
|
||||||
if (allocList[i].ptr == ptr)
|
if (allocList[i].ptr == ptr)
|
||||||
|
|
@ -301,7 +288,6 @@ namespace Memory
|
||||||
if (!ptr || !initialized)
|
if (!ptr || !initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(memMutex);
|
|
||||||
for (U32 i = 0; i < allocCount; ++i)
|
for (U32 i = 0; i < allocCount; ++i)
|
||||||
{
|
{
|
||||||
if (allocList[i].ptr == ptr)
|
if (allocList[i].ptr == ptr)
|
||||||
|
|
@ -331,7 +317,6 @@ namespace Memory
|
||||||
if (!newPtr)
|
if (!newPtr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(memMutex);
|
|
||||||
|
|
||||||
// Update existing record
|
// Update existing record
|
||||||
for (U32 i = 0; i < allocCount; ++i)
|
for (U32 i = 0; i < allocCount; ++i)
|
||||||
|
|
@ -453,7 +438,7 @@ void dFree(void* in_pFree)
|
||||||
|
|
||||||
void* dRealloc_r(void* in_pResize, dsize_t in_size, const char* fileName, const dsize_t line)
|
void* dRealloc_r(void* in_pResize, dsize_t in_size, const char* fileName, const dsize_t line)
|
||||||
{
|
{
|
||||||
return realloc(in_pResize,in_size);
|
return realloc(in_pResize, in_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue