Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
WtzLAS committed Jan 8, 2024
1 parent 51ba966 commit e29c676
Showing 1 changed file with 165 additions and 43 deletions.
208 changes: 165 additions & 43 deletions NorthstarDLL/shared/mimalloc.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <mimalloc.h>

typedef size_t (*MemAllocFailHandler_t)(size_t);

struct GenericMemoryStat_t
Expand All @@ -8,48 +10,168 @@ struct GenericMemoryStat_t

struct CMiMalloc
{
virtual void* AllocDebug(size_t nSize) {}
virtual void* Alloc(size_t nSize) {}
virtual void* ReallocDebug(void* pMem, size_t nSize) {}
virtual void* Realloc(void* pMem, size_t nSize) {}
virtual void FreeDebug(void* pMem) {}
virtual void Free(void* pMem) {}
virtual void* Expand_NoLongerSupportedDebug(void* pMem, size_t nSize) {}
virtual void* Expand_NoLongerSupported(void* pMem, size_t nSize) {}
virtual size_t GetSize(void* pMem) {}
virtual void PushAllocDbgInfo(const char* pFileName, int nLine) = 0;
virtual void PopAllocDbgInfo() = 0;
virtual __int32 CrtSetBreakAlloc(__int32 lNewBreakAlloc) = 0;
virtual int CrtSetReportMode(int nReportType, int nReportMode) = 0;
virtual int CrtIsValidHeapPointer(const void* pMem) = 0;
virtual int CrtIsValidPointer(const void* pMem, unsigned int size, int access) = 0;
virtual int CrtCheckMemory(void) = 0;
virtual int CrtSetDbgFlag(int nNewFlag) = 0;
virtual void CrtMemCheckpoint(_CrtMemState* pState) = 0;
virtual void DumpStats() = 0;
virtual void DumpStatsFileBase(char const* pchFileBase) = 0;
virtual size_t ComputeMemoryUsedBy(char const* pchSubStr) = 0;
virtual __int64 nullsub_1() = 0;
virtual void* CrtSetReportFile(int nRptType, void* hFile) = 0;
virtual void* CrtSetReportHook(void* pfnNewHook) = 0;
virtual int CrtDbgReport(int nRptType, const char* szFile, int nLine, const char* szModule, const char* pMsg) = 0;
virtual int heapchk() = 0;
virtual bool IsDebugHeap() = 0;
virtual void GetActualDbgInfo(const char*& pFileName, int& nLine) = 0;
virtual void RegisterAllocation(const char* pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime) = 0;
virtual void RegisterDeallocation(const char* pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime) = 0;
virtual int GetVersion() = 0;
virtual void CompactHeap() = 0;
virtual MemAllocFailHandler_t SetAllocFailHandler(MemAllocFailHandler_t pfnMemAllocFailHandler) = 0;
virtual void DumpBlockStats(void*) = 0;
virtual void SetStatsExtraInfo(const char* pMapName, const char* pComment) = 0;
virtual size_t MemoryAllocFailed() = 0;
virtual void CompactIncremental() = 0;
virtual void OutOfMemory(size_t nBytesAttempted = 0) = 0;
virtual void* RegionAllocDebug(int region, size_t nSize) = 0;
virtual void* RegionAlloc(int region, size_t nSize) = 0;
virtual void GlobalMemoryStatus(size_t* pUsedMemory, size_t* pFreeMemory) = 0;
virtual __int64 AllocateVirtualMemorySection(size_t numMaxBytes) = 0;
virtual int GetGenericMemoryStats(GenericMemoryStat_t** ppMemoryStats) = 0;
virtual void* AllocDebug(size_t nSize)
{
return mi_malloc(nSize);
}
virtual void* Alloc(size_t nSize)
{
return mi_malloc(nSize);
}

virtual void* ReallocDebug(void* pMem, size_t nSize)
{
return mi_realloc(pMem, nSize);
}
virtual void* Realloc(void* pMem, size_t nSize)
{
return mi_realloc(pMem, nSize);
}

virtual void FreeDebug(void* pMem)
{
return mi_free(pMem);
}
virtual void Free(void* pMem)
{
return mi_free(pMem);
}

virtual void* Expand_NoLongerSupportedDebug(void* pMem, size_t nSize)
{
return 0;
}
virtual void* Expand_NoLongerSupported(void* pMem, size_t nSize)
{
return 0;
}

virtual size_t GetSize(void* pMem)
{
return mi_usable_size(pMem);
}

virtual void PushAllocDbgInfo(const char* pFileName, int nLine) {}
virtual void PopAllocDbgInfo() {}

virtual __int32 CrtSetBreakAlloc(__int32 lNewBreakAlloc)
{
return 0;
}

virtual int CrtSetReportMode(int nReportType, int nReportMode)
{
return 0;
}

virtual int CrtIsValidHeapPointer(const void* pMem)
{
return 1;
}

virtual int CrtIsValidPointer(const void* pMem, unsigned int size, int access)
{
return 1;
}

virtual int CrtCheckMemory()
{
return 1;
}

virtual int CrtSetDbgFlag(int nNewFlag)
{
return 0;
}

virtual void CrtMemCheckpoint(_CrtMemState* pState) {}

// TODO 1
virtual void DumpStats() {}
virtual void DumpStatsFileBase(char const* pchFileBase) {}

virtual size_t ComputeMemoryUsedBy(char const* pchSubStr)
{
return 0;
}

virtual __int64 nullsub_1()
{
return 0xDC00000;
}

virtual void* CrtSetReportFile(int nRptType, void* hFile)
{
return 0;
}

virtual void* CrtSetReportHook(void* pfnNewHook)
{
return 0;
}

virtual int CrtDbgReport(int nRptType, const char* szFile, int nLine, const char* szModule, const char* pMsg)
{
return 0;
}

// TODO 2
virtual int heapchk() {}

virtual bool IsDebugHeap()
{
return false;
}

virtual void GetActualDbgInfo(const char*& pFileName, int& nLine) {}
virtual void RegisterAllocation(const char* pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime) {}
virtual void RegisterDeallocation(const char* pFileName, int nLine, size_t nLogicalSize, size_t nActualSize, unsigned nTime) {}

virtual int GetVersion()
{
return 1;
}

// TODO 3
virtual void CompactHeap() {}

virtual MemAllocFailHandler_t SetAllocFailHandler(MemAllocFailHandler_t pfnMemAllocFailHandler)
{
MemAllocFailHandler_t old = m_pfnFailHandler;
m_pfnFailHandler = pfnMemAllocFailHandler;
return old;
}

// TODO 4
virtual void DumpBlockStats(void* pMem) {}

virtual void SetStatsExtraInfo(const char* pMapName, const char* pComment) {}

virtual size_t MemoryAllocFailed()
{
return m_sMemoryAllocFailed;
}

// TODO 5
virtual void CompactIncremental() {}

virtual void OutOfMemory(size_t nBytesAttempted = 0) {}

// TODO 6
virtual void* RegionAllocDebug(int region, size_t nSize) {}
virtual void* RegionAlloc(int region, size_t nSize) {}

virtual void GlobalMemoryStatus(size_t* pUsedMemory, size_t* pFreeMemory) {}

virtual __int64 AllocateVirtualMemorySection(size_t numMaxBytes)
{
return 0;
}

virtual int GetGenericMemoryStats(GenericMemoryStat_t** ppMemoryStats) {}

virtual ~CMiMalloc() {};

MemAllocFailHandler_t m_pfnFailHandler;
size_t m_sMemoryAllocFailed;
};

0 comments on commit e29c676

Please sign in to comment.