mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Added guard for memory tracking.
This commit is contained in:
parent
46d6ff0b59
commit
a863185e57
1 changed files with 21 additions and 3 deletions
24
src/bgfx.cpp
24
src/bgfx.cpp
|
@ -114,15 +114,22 @@ namespace bgfx
|
|||
{
|
||||
public:
|
||||
AllocatorStub()
|
||||
#if BGFX_CONFIG_DEBUG
|
||||
: m_numBlocks(0)
|
||||
, m_maxBlocks(0)
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
{
|
||||
}
|
||||
|
||||
virtual void* alloc(size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
++m_numBlocks;
|
||||
m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks);
|
||||
#if BGFX_CONFIG_DEBUG
|
||||
{
|
||||
bx::LwMutexScope scope(m_mutex);
|
||||
++m_numBlocks;
|
||||
m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks);
|
||||
}
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
|
||||
BX_UNUSED(_file, _line);
|
||||
return ::malloc(_size);
|
||||
|
@ -132,7 +139,12 @@ namespace bgfx
|
|||
{
|
||||
if (NULL != _ptr)
|
||||
{
|
||||
--m_numBlocks;
|
||||
#if BGFX_CONFIG_DEBUG
|
||||
{
|
||||
bx::LwMutexScope scope(m_mutex);
|
||||
--m_numBlocks;
|
||||
}
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
|
||||
BX_UNUSED(_file, _line);
|
||||
::free(_ptr);
|
||||
|
@ -141,11 +153,14 @@ namespace bgfx
|
|||
|
||||
virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
#if BGFX_CONFIG_DEBUG
|
||||
if (NULL == _ptr)
|
||||
{
|
||||
bx::LwMutexScope scope(m_mutex);
|
||||
++m_numBlocks;
|
||||
m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks);
|
||||
}
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
|
||||
BX_UNUSED(_file, _line);
|
||||
return ::realloc(_ptr, _size);
|
||||
|
@ -157,8 +172,11 @@ namespace bgfx
|
|||
}
|
||||
|
||||
private:
|
||||
#if BGFX_CONFIG_DEBUG
|
||||
bx::LwMutex m_mutex;
|
||||
uint32_t m_numBlocks;
|
||||
uint32_t m_maxBlocks;
|
||||
#endif // BGFX_CONFIG_DEBUG
|
||||
};
|
||||
|
||||
static CallbackStub* s_callbackStub = NULL;
|
||||
|
|
Loading…
Reference in a new issue