mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added dynamic memory block.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "bx.h"
|
||||
#include "allocator.h"
|
||||
#include "uint32_t.h"
|
||||
|
||||
#if BX_COMPILER_MSVC_COMPATIBLE
|
||||
@@ -241,6 +242,43 @@ namespace bx
|
||||
uint32_t m_size;
|
||||
};
|
||||
|
||||
class MemoryBlock : public MemoryBlockI
|
||||
{
|
||||
public:
|
||||
MemoryBlock(ReallocatorI* _allocator)
|
||||
: m_allocator(_allocator)
|
||||
, m_data(NULL)
|
||||
, m_size(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MemoryBlock()
|
||||
{
|
||||
BX_FREE(m_allocator, m_data);
|
||||
}
|
||||
|
||||
virtual void* more(uint32_t _size = 0) BX_OVERRIDE
|
||||
{
|
||||
if (0 < _size)
|
||||
{
|
||||
m_size += _size;
|
||||
m_data = BX_REALLOC(m_allocator, m_data, m_size);
|
||||
}
|
||||
|
||||
return m_data;
|
||||
}
|
||||
|
||||
virtual uint32_t getSize() BX_OVERRIDE
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
private:
|
||||
ReallocatorI* m_allocator;
|
||||
void* m_data;
|
||||
uint32_t m_size;
|
||||
};
|
||||
|
||||
class SizerWriter : public WriterSeekerI
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user