Simplified allocator interface.
This commit is contained in:
Родитель
9970637bb4
Коммит
6dc6dd6148
|
@ -325,9 +325,10 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void* alloc(size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
virtual void* alloc(size_t _size, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
|
||||
{
|
||||
BX_UNUSED(_file, _line);
|
||||
void* ptr = ::malloc(_size);
|
||||
dbgPrintf("%s(%d): ALLOC %p of %d byte(s)\n", _file, _line, ptr, _size);
|
||||
++m_numBlocks;
|
||||
|
@ -335,20 +336,30 @@ public:
|
|||
return ptr;
|
||||
}
|
||||
|
||||
virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
return bx::alignedAlloc(this, _size, _align, _file, _line);
|
||||
}
|
||||
|
||||
virtual void free(void* _ptr, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
if (NULL != _ptr)
|
||||
{
|
||||
if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
|
||||
{
|
||||
dbgPrintf("%s(%d): FREE %p\n", _file, _line, _ptr);
|
||||
BX_UNUSED(_file, _line);
|
||||
::free(_ptr);
|
||||
--m_numBlocks;
|
||||
}
|
||||
else
|
||||
{
|
||||
bx::alignedFree(this, _ptr, _align, _file, _line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
|
||||
{
|
||||
BX_UNUSED(_file, _line);
|
||||
void* ptr = ::realloc(_ptr, _size);
|
||||
dbgPrintf("%s(%d): REALLOC %p (old %p) of %d byte(s)\n", _file, _line, ptr, _ptr, _size);
|
||||
|
||||
|
@ -361,6 +372,9 @@ public:
|
|||
return ptr;
|
||||
}
|
||||
|
||||
return bx::alignedRealloc(this, _ptr, _size, _align, _file, _line);
|
||||
}
|
||||
|
||||
void dumpStats() const
|
||||
{
|
||||
dbgPrintf("Allocator stats: num blocks %d (peak: %d)\n", m_numBlocks, m_maxBlocks);
|
||||
|
@ -380,7 +394,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
uint32_t height = 720;
|
||||
|
||||
bgfx::init(&callback, &allocator);
|
||||
bgfx::reset(width, height, BGFX_RESET_CAPTURE);
|
||||
bgfx::reset(width, height, BGFX_RESET_CAPTURE|BGFX_RESET_MSAA_X16);
|
||||
|
||||
// Enable debug text.
|
||||
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
||||
|
|
30
src/bgfx.cpp
30
src/bgfx.cpp
|
@ -144,7 +144,9 @@ namespace bgfx
|
|||
{
|
||||
}
|
||||
|
||||
virtual void* alloc(size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
virtual void* alloc(size_t _size, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
|
||||
{
|
||||
#if BGFX_CONFIG_MEMORY_TRACKING
|
||||
{
|
||||
|
@ -154,14 +156,18 @@ namespace bgfx
|
|||
}
|
||||
#endif // BGFX_CONFIG_MEMORY_TRACKING
|
||||
|
||||
BX_UNUSED(_file, _line);
|
||||
return ::malloc(_size);
|
||||
}
|
||||
|
||||
virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
return bx::alignedAlloc(this, _size, _align, _file, _line);
|
||||
}
|
||||
|
||||
virtual void free(void* _ptr, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
if (NULL != _ptr)
|
||||
{
|
||||
if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
|
||||
{
|
||||
#if BGFX_CONFIG_MEMORY_TRACKING
|
||||
{
|
||||
bx::LwMutexScope scope(m_mutex);
|
||||
|
@ -170,12 +176,18 @@ namespace bgfx
|
|||
}
|
||||
#endif // BGFX_CONFIG_MEMORY_TRACKING
|
||||
|
||||
BX_UNUSED(_file, _line);
|
||||
::free(_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
bx::alignedFree(this, _ptr, _align, _file, _line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) BX_OVERRIDE
|
||||
{
|
||||
if (BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT >= _align)
|
||||
{
|
||||
#if BGFX_CONFIG_MEMORY_TRACKING
|
||||
if (NULL == _ptr)
|
||||
|
@ -186,10 +198,12 @@ namespace bgfx
|
|||
}
|
||||
#endif // BGFX_CONFIG_MEMORY_TRACKING
|
||||
|
||||
BX_UNUSED(_file, _line);
|
||||
return ::realloc(_ptr, _size);
|
||||
}
|
||||
|
||||
return bx::alignedRealloc(this, _ptr, _size, _align, _file, _line);
|
||||
}
|
||||
|
||||
void checkLeaks()
|
||||
{
|
||||
#if BGFX_CONFIG_MEMORY_TRACKING
|
||||
|
@ -762,7 +776,7 @@ namespace bgfx
|
|||
|
||||
s_threadIndex = BGFX_MAIN_THREAD_MAGIC;
|
||||
|
||||
s_ctx = BX_ALIGNED_NEW(g_allocator, 16, Context);
|
||||
s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16);
|
||||
s_ctx->init();
|
||||
|
||||
BX_TRACE("Init complete.");
|
||||
|
@ -776,7 +790,7 @@ namespace bgfx
|
|||
Context* ctx = s_ctx; // it's going to be NULLd inside shutdown.
|
||||
ctx->shutdown();
|
||||
|
||||
BX_ALIGNED_DELETE(g_allocator, 16, ctx);
|
||||
BX_ALIGNED_DELETE(g_allocator, ctx, 16);
|
||||
|
||||
if (NULL != s_callbackStub)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче