2022-07-22 16:34:10 +02:00
|
|
|
#ifndef MEMSTD_H
|
|
|
|
#define MEMSTD_H
|
|
|
|
|
2023-06-29 00:23:47 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-07-22 16:34:10 +02:00
|
|
|
class IMemAlloc
|
|
|
|
{
|
|
|
|
public:
|
2023-06-26 22:34:24 +02:00
|
|
|
// Same functions internally.
|
2023-06-29 00:23:47 +02:00
|
|
|
virtual void* InternalAlloc(size_t nSize, const char* pFileName, int nLine) = 0;
|
2023-06-26 22:34:24 +02:00
|
|
|
virtual void* Alloc(size_t nSize) = 0;
|
|
|
|
|
|
|
|
// Same functions internally.
|
2023-06-29 00:23:47 +02:00
|
|
|
virtual void* InternalRealloc(void* pMem, size_t nSize, const char* pFileName, int nLine) = 0;
|
2023-06-26 22:34:24 +02:00
|
|
|
virtual void* Realloc(void* pMem, size_t nSize) = 0;
|
|
|
|
|
|
|
|
// Same as Free, but takes debug parameters.
|
|
|
|
virtual void InternalFree(void* pMem, const char* pFileName, int nLine) = 0;
|
|
|
|
virtual void Free(void* pMem) = 0;
|
|
|
|
|
|
|
|
virtual size_t GetSize(void* pMem) = 0;
|
2022-07-22 16:34:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
class CStdMemAlloc : public IMemAlloc{};
|
|
|
|
|
2023-06-25 11:37:52 +02:00
|
|
|
inline CStdMemAlloc* (*CreateGlobalMemAlloc)() = nullptr;
|
|
|
|
inline CStdMemAlloc* g_pMemAllocSingleton = nullptr;
|
2022-07-22 16:34:10 +02:00
|
|
|
|
2023-06-18 01:16:24 +02:00
|
|
|
inline IMemAlloc* MemAllocSingleton()
|
2022-07-22 16:34:10 +02:00
|
|
|
{
|
2023-06-25 11:37:52 +02:00
|
|
|
if (!g_pMemAllocSingleton)
|
2022-07-22 16:34:10 +02:00
|
|
|
{
|
2023-06-25 11:37:52 +02:00
|
|
|
g_pMemAllocSingleton = CreateGlobalMemAlloc();
|
2022-07-22 16:34:10 +02:00
|
|
|
}
|
2023-06-25 11:37:52 +02:00
|
|
|
return g_pMemAllocSingleton;
|
2022-07-22 16:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MEMSTD_H
|